-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathvalidation-error.js
More file actions
27 lines (23 loc) · 944 Bytes
/
validation-error.js
File metadata and controls
27 lines (23 loc) · 944 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// The "details" property of the ValidationError must be an array of objects
// containing at least two properties. The "name" and "type" properties are
// required.
const errorsPattern = [Match.ObjectIncluding({
name: String,
type: String
})];
ValidationError = class extends Meteor.Error {
constructor(errors, message = ValidationError.DEFAULT_MESSAGE) {
check(errors, errorsPattern);
check(message, String);
return super(ValidationError.ERROR_CODE, message, errors);
}
// Static method checking if a given Meteor.Error is an instance of
// ValidationError.
static is(err) {
return err instanceof Meteor.Error && err.error === ValidationError.ERROR_CODE;
};
};
// Universal validation error code to be use in applications and packages.
ValidationError.ERROR_CODE = 'validation-error';
// Default validation error message that can be changed globally.
ValidationError.DEFAULT_MESSAGE = 'Validation failed';