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