mirror of
https://github.com/glitch-soc/mastodon.git
synced 2024-11-14 12:14:24 -05:00
2c51bc0ca5
* Add eslint-plugin-promise to detect uncaught rejections * Move alert generation for errors to actions/alert * Add missing rejection handling for Promises * Use catch() instead of onReject on then() Then it will catches rejection from onFulfilled. This detection can be disabled by `allowThen` option, though.
18 lines
429 B
JavaScript
18 lines
429 B
JavaScript
import { showAlertForError } from '../actions/alerts';
|
|
|
|
const defaultFailSuffix = 'FAIL';
|
|
|
|
export default function errorsMiddleware() {
|
|
return ({ dispatch }) => next => action => {
|
|
if (action.type && !action.skipAlert) {
|
|
const isFail = new RegExp(`${defaultFailSuffix}$`, 'g');
|
|
|
|
if (action.type.match(isFail)) {
|
|
dispatch(showAlertForError(action.error));
|
|
}
|
|
}
|
|
|
|
return next(action);
|
|
};
|
|
};
|