Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@tai2
Created April 4, 2019 13:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tai2/d99055284b0e456613c3863f04397616 to your computer and use it in GitHub Desktop.
Save tai2/d99055284b0e456613c3863f04397616 to your computer and use it in GitHub Desktop.
Dump stack trace to console when FSA contains an error.
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