~cytrogen/masto-fe

ref: 2f95adc06fbfae22e8f9b4df212938108f5e295c masto-fe/app/javascript/mastodon/middleware/errors.js -rw-r--r-- 429 bytes
2f95adc0 — ThibG Merge pull request #1142 from ThibG/glitch-soc/merge-upstream 6 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));
      }
    }

    return next(action);
  };
};