Files
ncd-fe/app/soapbox/middleware/errors.js
2021-10-20 16:27:36 -05:00

19 lines
516 B
JavaScript

import { showAlertForError } from '../actions/alerts';
const isFailType = type => type.endsWith('_FAIL');
const isRememberFailType = type => type.endsWith('_REMEMBER_FAIL');
const shouldShowError = ({ type, skipAlert }) => {
return !skipAlert && isFailType(type) && !isRememberFailType(type);
};
export default function errorsMiddleware() {
return ({ dispatch }) => next => action => {
if (shouldShowError(action)) {
dispatch(showAlertForError(action.error));
}
return next(action);
};
}