Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move validation error class decision
- Loading branch information
1 parent
20be616
commit 274b4b2
Showing
4 changed files
with
67 additions
and
65 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
4 changes: 2 additions & 2 deletions
4
src/errors/ValidationError.js → src/errors/DefaultValidationError.js
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,8 +1,8 @@ | ||
class ValidationError extends Error { | ||
class DefautValidationError extends Error { | ||
constructor(errors) { | ||
super('Invalid Attributes'); | ||
this.details = errors; | ||
} | ||
} | ||
|
||
module.exports = ValidationError; | ||
module.exports = DefautValidationError; |
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,10 +1,8 @@ | ||
const ValidationError = require('./ValidationError'); | ||
|
||
module.exports = { | ||
classAsSecondParam: (ErroneousPassedClass) => new Error(`You passed the structure class as the second parameter of attributes(). The expected usage is \`attributes(schema)(${ ErroneousPassedClass.name || 'StructureClass' })\`.`), | ||
nonObjectAttributes: () => new TypeError('#attributes can\'t be set to a non-object.'), | ||
arrayOrIterable: () => new TypeError('Value must be iterable or array-like.'), | ||
missingDynamicType: (attributeName) => new Error(`Missing dynamic type for attribute: ${ attributeName }.`), | ||
invalidType: (attributeName) => new TypeError(`Attribute type must be a constructor or the name of a dynamic type: ${ attributeName }.`), | ||
invalidAttributes: (errors, CustomValidationError) => new (CustomValidationError || ValidationError)(errors) | ||
invalidAttributes: (errors, StructureValidationError) => new StructureValidationError(errors) | ||
}; |
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