Created
April 4, 2019 13:51
-
-
Save tai2/d99055284b0e456613c3863f04397616 to your computer and use it in GitHub Desktop.
Dump stack trace to console when FSA contains an error.
This file contains 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 { Dispatch } from 'redux' | |
type ErrorAction = { payload: Error } | |
function isErrorAction(action: any): action is ErrorAction { | |
return (<ErrorAction>action).payload instanceof Error | |
} | |
const errorLoggerMiddleware = (store: any) => (next: Dispatch) => ( | |
action: any | |
) => { | |
if (isErrorAction(action)) { | |
console.error(action.payload) | |
} | |
return next(action) | |
} | |
export default errorLoggerMiddleware |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment