2018-04-02 22:51:02 +10:00
|
|
|
import { showAlertForError } from '../actions/alerts';
|
2016-10-19 02:09:45 +11:00
|
|
|
|
|
|
|
const defaultFailSuffix = 'FAIL';
|
|
|
|
|
|
|
|
export default function errorsMiddleware() {
|
|
|
|
return ({ dispatch }) => next => action => {
|
2017-02-27 09:06:27 +11:00
|
|
|
if (action.type && !action.skipAlert) {
|
2016-10-19 02:09:45 +11:00
|
|
|
const isFail = new RegExp(`${defaultFailSuffix}$`, 'g');
|
|
|
|
|
|
|
|
if (action.type.match(isFail)) {
|
2020-03-29 03:59:45 +11:00
|
|
|
dispatch(showAlertForError(action.error, action.skipNotFound));
|
2016-10-19 02:09:45 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return next(action);
|
|
|
|
};
|
|
|
|
};
|