Skip to content

Error handling on action payload #350

Open
@sombreroEnPuntas

Description

@sombreroEnPuntas

I'm following the docs to implement redux-actions in a project.
https://redux-actions.js.org/api/createaction#createactiontype

When I get to the error handling example:

const noop = createAction('NOOP');

const error = new TypeError('not a number');
expect(noop(error)).to.deep.equal({
  type: 'NOOP',
  payload: error,
  error: true
});

I noticed that when I pass an error for testing, like this:

const {
  successAction,
  errorAction
} = createActions({
  SUCCEESS_ACTION: payload => ({
    data: payload
  }),
  ERROR_ACTION: payload => ({
    error: payload
  }),
});

  try {
    let data;
    // ... some stuff to fetch data :)

    throw Error('Bad times on the internetz');

    successAction(data);
  } catch (error) {
    errorAction(error):
  }

The action is now:

{
  type: 'ERROR_ACTION',
  payload: {}, // Expected it to be 'Error: Bad times on the internetz' instance
  error: true
}

Did I write a wrong implementation? What should be the right way to get the error?
I want to be able to reduce the action with an error payload and save the error to the store for further steps (like showing a toast with the error message to the user)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions