~cytrogen/masto-fe

ref: 9d39b111f18faac3812558cd29444a9bd48c959c masto-fe/app/javascript/mastodon/middleware/errors.js -rw-r--r-- 449 bytes
9d39b111 — Matt Jankowski Expand coverage for "system checks" (#24216) 3 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import { showAlertForError } from '../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);
  };
}