Skip to content

Set payload equal to error if payload is instanceof Error #65

@danny-andrews

Description

@danny-andrews

I already made a note of this in #43, but I wanted to promote it to its own issue.

I personally think that if you pass an error in as the payload, it should bypass your custom payloadCreator logic and just set the payload equal to the passed-in error. Otherwise, you have to add an error check in each of your action creators to achieve the same effect.
Example:

const createCoolAction = createAction(COOL_ACTION_TYPE, spec => {
  const {zipCode, id} = spec;
  return {body: {zipCode, id}};
});

So, if I do something like, createCoolAction(new Error('Something bad happened')), the payload will be set to {body: {zipCode: undefined, id: undefined}} instead of just the error object itself. To fix this, I could add an error check, but I don't want to have to do this in every one of my action creators.

I'd be happy to make an MR for this.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions