-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: improve
SubmissionError
detection
Now event after obfuscation, or importing SubmissionForm from a different context, `isSubmissionError` will return true only for `SubmissionError` Closes #4641
- Loading branch information
1 parent
638dc44
commit e705b7c
Showing
9 changed files
with
160 additions
and
458 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
// @flow | ||
import ExtendableError from 'es6-error' | ||
|
||
class SubmissionError extends ExtendableError { | ||
const __FLAG__ = '@@redux-form/submission-error-flag' | ||
|
||
export class SubmissionError extends ExtendableError { | ||
/** @private */ | ||
static __FLAG__ = __FLAG__ | ||
|
||
constructor(errors: Object) { | ||
super('Submit Validation Failed') | ||
this.errors = errors | ||
} | ||
} | ||
|
||
export default SubmissionError | ||
export function isSubmissionError(error: any): boolean { | ||
return (error && error.constructor && error.constructor.__FLAG__ === __FLAG__) === true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// @flow | ||
|
||
import ExtendableError from 'es6-error' | ||
import { isSubmissionError, SubmissionError } from '../SubmissionError' | ||
|
||
class FakeSubmissionError { | ||
static __FLAG__ = '@@redux-form/submission-error-flag' | ||
} | ||
|
||
describe('isSubmissionError', () => { | ||
it('should return `true` only when argument is instance `SubmissionError`', () => { | ||
expect(isSubmissionError(new SubmissionError({}))).toBe(true) | ||
expect(isSubmissionError(new FakeSubmissionError())).toBe(true) | ||
expect(isSubmissionError(new Error())).toBe(false) | ||
expect(isSubmissionError(new ExtendableError())).toBe(false) | ||
expect(isSubmissionError({})).toBe(false) | ||
expect(isSubmissionError()).toBe(false) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.