diff --git a/src/__tests__/createAction-test.js b/src/__tests__/createAction-test.js index 1265dd9a..336f3136 100644 --- a/src/__tests__/createAction-test.js +++ b/src/__tests__/createAction-test.js @@ -130,5 +130,16 @@ describe('createAction()', () => { meta: { foo: 'bar' } }); }); + + it('set error to true if payloadCreator return an Error object', () => { + const errObj = new TypeError('this is an error'); + const actionCreator = createAction(type, () => errObj); + const errAction = actionCreator('invalid arguments'); + expect(errAction).to.deep.equal({ + type, + payload: errObj, + error: true + }); + }); }); }); diff --git a/src/createAction.js b/src/createAction.js index 532610d7..304c2d07 100644 --- a/src/createAction.js +++ b/src/createAction.js @@ -17,7 +17,7 @@ export default function createAction(type, payloadCreator, metaCreator) { action.payload = payload; } - if (hasError) { + if (hasError || payload instanceof Error) { // Handle FSA errors where the payload is an Error object. Set error. action.error = true; }