Last active
October 20, 2020 12:51
-
-
Save karol-majewski/56172ce67e9ec86a0435378f69930cc1 to your computer and use it in GitHub Desktop.
The simplest error handling middleware for Redux
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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