This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
2019-02-10 12:28:29 -08:00
|
|
|
import { showAlertForError } from 'flavours/glitch/actions/alerts';
|
2016-10-18 08:09:45 -07:00
|
|
|
|
|
|
|
const defaultFailSuffix = 'FAIL';
|
|
|
|
|
|
|
|
export default function errorsMiddleware() {
|
|
|
|
return ({ dispatch }) => next => action => {
|
2017-02-26 14:06:27 -08:00
|
|
|
if (action.type && !action.skipAlert) {
|
2016-10-18 08:09:45 -07:00
|
|
|
const isFail = new RegExp(`${defaultFailSuffix}$`, 'g');
|
|
|
|
|
|
|
|
if (action.type.match(isFail)) {
|
2019-02-10 12:28:29 -08:00
|
|
|
dispatch(showAlertForError(action.error));
|
2016-10-18 08:09:45 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return next(action);
|
|
|
|
};
|
|
|
|
};
|