Skip to content

Instantly share code, notes, and snippets.

@karol-majewski
Last active October 20, 2020 12:51
Show Gist options
  • Save karol-majewski/56172ce67e9ec86a0435378f69930cc1 to your computer and use it in GitHub Desktop.
Save karol-majewski/56172ce67e9ec86a0435378f69930cc1 to your computer and use it in GitHub Desktop.
The simplest error handling middleware for Redux
import { Action, AnyAction, Middleware } from 'redux';
const errorMiddleware: Middleware =
store =>
next =>
(action: AnyAction) => {
if (action.error instanceof Error) {
store.dispatch({
type: '@@internal/EXCEPTION_THROWN',
payload: action.error.message,
})
}
return next(action);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment