The code powering m.abunchtell.com https://m.abunchtell.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

55 lines
1.2 KiB

  1. import { defineMessages } from 'react-intl';
  2. const messages = defineMessages({
  3. unexpectedTitle: { id: 'alert.unexpected.title', defaultMessage: 'Oops!' },
  4. unexpectedMessage: { id: 'alert.unexpected.message', defaultMessage: 'An unexpected error occurred.' },
  5. });
  6. export const ALERT_SHOW = 'ALERT_SHOW';
  7. export const ALERT_DISMISS = 'ALERT_DISMISS';
  8. export const ALERT_CLEAR = 'ALERT_CLEAR';
  9. export function dismissAlert(alert) {
  10. return {
  11. type: ALERT_DISMISS,
  12. alert,
  13. };
  14. };
  15. export function clearAlert() {
  16. return {
  17. type: ALERT_CLEAR,
  18. };
  19. };
  20. export function showAlert(title = messages.unexpectedTitle, message = messages.unexpectedMessage) {
  21. return {
  22. type: ALERT_SHOW,
  23. title,
  24. message,
  25. };
  26. };
  27. export function showAlertForError(error) {
  28. if (error.response) {
  29. const { data, status, statusText } = error.response;
  30. if (status === 404 || status === 410) {
  31. // Skip these errors as they are reflected in the UI
  32. return {};
  33. }
  34. let message = statusText;
  35. let title = `${status}`;
  36. if (data.error) {
  37. message = data.error;
  38. }
  39. return showAlert(title, message);
  40. } else {
  41. console.error(error);
  42. return showAlert();
  43. }
  44. }