You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
554 B
19 lines
554 B
2 years ago
|
import { Middleware } from 'redux';
|
||
6 years ago
|
import { showAlertForError } from 'flavours/glitch/actions/alerts';
|
||
2 years ago
|
import { RootState } from '..';
|
||
8 years ago
|
|
||
|
const defaultFailSuffix = 'FAIL';
|
||
|
|
||
2 years ago
|
export const errorsMiddleware: Middleware<Record<string, never>, RootState> =
|
||
|
({ dispatch }) => next => action => {
|
||
8 years ago
|
if (action.type && !action.skipAlert) {
|
||
8 years ago
|
const isFail = new RegExp(`${defaultFailSuffix}$`, 'g');
|
||
|
|
||
|
if (action.type.match(isFail)) {
|
||
5 years ago
|
dispatch(showAlertForError(action.error, action.skipNotFound));
|
||
8 years ago
|
}
|
||
|
}
|
||
|
|
||
|
return next(action);
|
||
|
};
|