JSPM

redux-catch-async

1.2.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q9632F
  • License MIT

Error handling middleware for redux that supports sync and async errors

Package Exports

  • redux-catch-async

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (redux-catch-async) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

redux-catch-async

Error catcher middleware for Redux reducers and synchronous or asynchronous middlewares. This snippet was inspired and adapted from redux-catch.

Usage

Apply redux-catch-async as your first middleware

import { createStore, applyMiddleware } from 'redux';

import reduxCatchAsync from 'redux-catch-async';

import reducer from './reducer';

function errorHandler(error, getState, lastAction, dispatch) {
  // error - the error object thrown from reducers or middleware
  // getState - function for returning the state of the redux store
  // lastAction - action that resulted in a caught error
  // dispatch - function for dispatching actions if needed
}

// Ensure that reduxCatchAsync is always applied as the first middleware
// so that it can catch middleware errors.
const store = createStore(
  reducer,
  applyMiddleware(reduxCatchAsync(errorHandler)),
);

Tips

  • The ErrorHandler function is a great place to set up sentry logging / error analytics.
  • Remember to log getState / lastAction as they are great for debugging.
  • You have the freedom to do a bit of application state coupling here, for use-cases such as displaying a global error (for example).
  • Changing the position from which you apply reduxCatchAsync opens the possibility of selectively catching errors from some of your other middleware.