Error handling on action payload

Author: sombreroEnPuntasCreated Aug 9, 2019Updated May 15, 2020

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)

Source: redux-utilities/redux-actions