0.0.3 • Published 5 years ago

redux-thunk-handle-rejection v0.0.3

Weekly downloads
9
License
MIT
Repository
-
Last release
5 years ago

redux-thunk-handle-rejection

Improved redux-thunk.

You can handle the result of thunk.

Usecase Example

In case you might want to catch unhandled Promise rejection.

const thunk = createThunk<RootState, undefined>({
  actionResultHandler(actionResult: any) {
    // TODO: technically this may not be accurate if BlueBird instance is containerd
    if (actionResult instanceof Promise) {
      return actionResult.catch(err => {
        if (err.status === 401) {
          console.log('need authorization');
        }
        elseif (err.status === 500) {
          console.log('unexpected error occurred');
        }
      });
    }
    return actionResult;
  }
});