Skip to content
This repository was archived by the owner on Aug 23, 2022. It is now read-only.

Commit 9d9cef8

Browse files
committed
Handle thrown errors correctly. Fixes #877
1 parent d7ebf02 commit 9d9cef8

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/actions/field-actions.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,11 @@ function createFieldActions(s = defaultStrategies) {
214214
setSubmitted(model, true),
215215
setValidity(model, response),
216216
]));
217-
}).catch(error => {
217+
}).catch(rejection => {
218+
const error = rejection instanceof Error
219+
? rejection.message
220+
: rejection;
221+
218222
dispatch(batch(model, [
219223
setSubmitFailed(model),
220224
errorsAction(model, error, { async: true }),

test/field-actions-spec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,6 +1510,25 @@ Object.keys(testContexts).forEach((testKey) => {
15101510

15111511
store.dispatch(action);
15121512
});
1513+
1514+
it('should capture thrown errors', (done) => {
1515+
const store = createTestStore(testCreateStore({
1516+
testForm: formReducer('test'),
1517+
}), done);
1518+
1519+
store.when(actionTypes.SET_ERRORS, (_, action) => {
1520+
assert.containSubset(action, {
1521+
model: 'test',
1522+
errors: 'Async error',
1523+
});
1524+
});
1525+
1526+
const action = actions.submit('test', new Promise(() => {
1527+
throw new Error('Async error');
1528+
}));
1529+
1530+
store.dispatch(action);
1531+
});
15131532
});
15141533

15151534
describe('validate() (thunk)', () => {

0 commit comments

Comments
 (0)