Skip to content

Instantly share code, notes, and snippets.

@everdimension
Created February 12, 2018 23:34
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 everdimension/86d840e21991e70219fab0cfcb558f3e to your computer and use it in GitHub Desktop.
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
/**
* 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