errors.js 450 B

1234567891011121314151617
  1. import { showAlertForError } from '../actions/alerts';
  2. const defaultFailSuffix = 'FAIL';
  3. export default function errorsMiddleware() {
  4. return ({ dispatch }) => next => action => {
  5. if (action.type && !action.skipAlert) {
  6. const isFail = new RegExp(`${defaultFailSuffix}$`, 'g');
  7. if (action.type.match(isFail)) {
  8. dispatch(showAlertForError(action.error, action.skipNotFound));
  9. }
  10. }
  11. return next(action);
  12. };
  13. };