Skip to content

Commit f0f3c94

Browse files
xiaohanzhangyangmillstheory
authored andcommitted
set error to true when payload instanceof Error (#136)
Close #138.
1 parent 1e818ab commit f0f3c94

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/__tests__/createAction-test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,5 +130,16 @@ describe('createAction()', () => {
130130
meta: { foo: 'bar' }
131131
});
132132
});
133+
134+
it('set error to true if payloadCreator return an Error object', () => {
135+
const errObj = new TypeError('this is an error');
136+
const actionCreator = createAction(type, () => errObj);
137+
const errAction = actionCreator('invalid arguments');
138+
expect(errAction).to.deep.equal({
139+
type,
140+
payload: errObj,
141+
error: true
142+
});
143+
});
133144
});
134145
});

src/createAction.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default function createAction(type, payloadCreator, metaCreator) {
1717
action.payload = payload;
1818
}
1919

20-
if (hasError) {
20+
if (hasError || payload instanceof Error) {
2121
// Handle FSA errors where the payload is an Error object. Set error.
2222
action.error = true;
2323
}

0 commit comments

Comments
 (0)