Created
February 12, 2018 23:34
-
-
Save everdimension/86d840e21991e70219fab0cfcb558f3e to your computer and use it in GitHub Desktop.
A way to describe response error while conforming to Flux Standard Action and passing request info
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
/** | |
* see redux-actions lib to see how `createAction` works | |
* https://redux-actions.js.org/docs/api/createAction.html | |
*/ | |
import { createAction } from 'redux-act(ions)'; | |
class ResponseError extends Error { /* add a `this.request` prop */ } | |
/** add a `meta` field when payload in an Error */ | |
const receiveEntity = createAction('SOME_TYPE', identity, payload => { | |
if (payload instanceof ResponseError) { | |
return { request: payload.request }; | |
} | |
return undefined; | |
}); | |
dispatch(receiveEntity(new ResponseError({ id: 123 }))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment