gab-social/app/javascript/gabsocial/middleware/errors.js

18 lines
429 B
JavaScript
Raw Normal View History

2019-07-02 08:10:25 +01:00
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);
};
};