Skip to content

Commit

Permalink
Merge pull request #74 from smartprocure/fix/generic_error_handling
Browse files Browse the repository at this point in the history
FIX: do not have special handling for top level errors
  • Loading branch information
sandhya-spend authored Nov 4, 2024
2 parents 7ea4571 + 0838629 commit 2690c33
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.14.1

- FIX: errors[''] is nothing special, remove special handling for it.

# 0.14.0

- Support form errors via an `ValidationError` on `submit`.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mobx-autoform",
"version": "0.14.0",
"version": "0.14.1",
"description": "Ridiculously simple form state management with mobx",
"type": "module",
"main": "dist/cjs/index.js",
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export default ({
return await configSubmit(form.getSnapshot(), form)
} catch (err) {
if (err instanceof ValidationError) {
state.errors = { '': err.message, ...err.cause }
state.errors = err.cause
}
throw err
}
Expand Down
5 changes: 3 additions & 2 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,6 @@ describe('submit()', () => {
'location.addresses.0.tenants.0': ['invalid format'],
})
expect(form.errors).toEqual({
'': 'My submit failed',
'location.addresses.0.tenants.0': ['invalid format'],
})
expect(form.submitError).toBe('My submit failed')
Expand All @@ -431,6 +430,7 @@ describe('submit()', () => {
const submit = async () => {
throw new ValidationError('My submit failed', {
'location.addresses.0.tenants.0': ['invalid format'],
'': ['top level error'],
})
}
form = Form({ fields: goodFields, value: goodValue, submit })
Expand All @@ -439,10 +439,11 @@ describe('submit()', () => {
expect(form.submit.state.error.message).toBe('My submit failed')
expect(form.submit.state.error.cause).toEqual({
'location.addresses.0.tenants.0': ['invalid format'],
'': ['top level error'],
})
expect(form.errors).toEqual({
'': 'My submit failed',
'location.addresses.0.tenants.0': ['invalid format'],
'': ['top level error'],
})
expect(form.submitError).toBe('My submit failed')
expect(result).toBeUndefined()
Expand Down

0 comments on commit 2690c33

Please sign in to comment.