about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/middleware/errors.js
blob: ade529a4ebe441deb7b639c6dcba80fe4367dc42 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import { showAlertForError } from 'flavours/glitch/actions/alerts';

const defaultFailSuffix = 'FAIL';

export default function errorsMiddleware() {
  return ({ dispatch }) => next => action => {
    if (action.type && !action.skipAlert) {
      const isFail = new RegExp(`${defaultFailSuffix}$`, 'g');

      if (action.type.match(isFail)) {
        dispatch(showAlertForError(action.error, action.skipNotFound));
      }
    }

    return next(action);
  };
};