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