-
Notifications
You must be signed in to change notification settings - Fork 2
/
generateFromList.js
31 lines (26 loc) · 986 Bytes
/
generateFromList.js
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
28
29
30
31
const { createErrorClass, createErrorsList, helpers } = require('../src')('optional-custom-source');
const RuntimeError = createErrorClass('RuntimeError', 'Error during validation.', Error);
const ValidationError = createErrorClass('ValidationError', 'Error during validation.', Error);
const UserValidationError = createErrorClass(
'UserValidationError',
'Error during user validation.',
ValidationError
);
const UserValidationErrors = createErrorsList({
NO_NAME: 'Please specify name.',
NO_LOGIN: 'Please specify login.',
}, UserValidationError);
try {
try {
throw new UserValidationErrors.NO_NAME({ user: { name: null } });
} catch (e) {
// e instanceof UserValidationError; // true
// e instanceof ValidationError; // true
// e instanceof Error; // true
// e instanceof RuntimeError; // false
throw new RuntimeError(null, e);
}
} catch (e) {
// e instanceof RuntimeError; // true
helpers.hasErrorClass(e, ValidationError); // true
}