-
Notifications
You must be signed in to change notification settings - Fork 0
/
Error.js
58 lines (54 loc) · 1.96 KB
/
Error.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
49
50
51
52
53
54
55
56
57
58
/**
* Base class for errors.
* You probably shouldn't throw one of these, but instead subclass it or use
* one of the supplied Error types below.
*/
function ExtendableError() {
var tmp = Error.apply(this, arguments);
this.stack = tmp.stack;
this.stack = this.stack.replace(/^Error/, this.name);
this.message = tmp.message;
}
ExtendableError.prototype = Object.create(Error.prototype);
ExtendableError.prototype.name = 'ExtendableError';
ExtendableError.prototype.constructor = ExtendableError;
/**
* Throw when input is unexceptable.
*/
function InputError(fieldName, humanReadableExpectedValue) {
ExtendableError.call(this, fieldName + ' has an invalid value');
this.fieldName = fieldName;
this.humanReadableExpectedValue = humanReadableExpectedValue;
}
InputError.prototype = Object.create(ExtendableError.prototype);
InputError.prototype.name = 'InputError';
InputError.prototype.constructor = InputError;
/**
* Throw when function isn't ready to be called, and doesn't want to deal with
* queues and asynchronous stuff.
*/
function NotReadyError() {
ExtendableError.apply(this, arguments);
}
NotReadyError.prototype = Object.create(ExtendableError.prototype);
NotReadyError.prototype.name = 'NotReadyError';
NotReadyError.prototype.constructor = NotReadyError;
/**
* Throw if after doing a piece of logic something should be true and it's not.
*/
function LogicError() {
ExtendableError.apply(this, arguments);
}
NotReadyError.prototype = Object.create(ExtendableError.prototype);
NotReadyError.prototype.name = 'NotReadyError';
NotReadyError.prototype.constructor = NotReadyError;
/**
* Throw if a piece of functionality isn't implemented yet but it was used
* anyway.
*/
function NotImplementedError() {
ExtendableError.apply(this, arguments);
}
NotImplementedError.prototype = Object.create(ExtendableError.prototype);
NotImplementedError.prototype.name = 'NotImplementedError';
NotImplementedError.prototype.constructor = NotImplementedError;