-
Notifications
You must be signed in to change notification settings - Fork 1
/
errors.js
48 lines (41 loc) · 1.3 KB
/
errors.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
class ExtendableError extends Error {
constructor(message) {
super(message)
this.name = this.constructor.name
if (typeof Error.captureStackTrace === 'function') {
Error.captureStackTrace(this, this.constructor)
} else {
this.stack = (new Error(message)).stack
}
}
}
class SchemaIsNotDefinedError extends ExtendableError {
constructor (name) {
super(`Schema "${name}" is not defined!`)
}
}
class WrongRefTypeError extends ExtendableError {
constructor (refValue) {
super(`Expected "$ref" to be string, get ${typeof refValue} type`)
}
}
class WrongFormatterError extends ExtendableError {
constructor (formatter) {
super(`Expected formatter to be function or object, get ${typeof formatter} type`)
}
}
class AttributeNotFoundError extends ExtendableError {
constructor (attribute) {
super(`Attribute "${attribute}" required in strict mode`)
}
}
class WrongTypeError extends ExtendableError {
constructor (name, type, data) {
super(`Expected "${name}" to be ${type}, get ${typeof data} type`)
}
}
exports.SchemaIsNotDefinedError = SchemaIsNotDefinedError
exports.WrongRefTypeError = WrongRefTypeError
exports.WrongFormatterError = WrongFormatterError
exports.AttributeNotFoundError = AttributeNotFoundError
exports.WrongTypeError = WrongTypeError