This repository has been archived by the owner on May 8, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Exceptions.js
104 lines (96 loc) · 2.34 KB
/
Exceptions.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/**
* A required parameter is missing.
*
* @extends {Error}
* @class
*/
class RequiredParameterException extends Error {
/**
* Creates a RequiredParameterException
*
* @param {string} paramName the name of the parameter
*/
constructor(paramName) {
if (!paramName) {
throw new Error('RequiredParameterException requires a parameter name');
}
super(`Parameter "${paramName}" must be specified.`);
}
}
/**
* The requested index of the array was out of bounds.
*
* @extends {Error}
* @class
*/
class IndexOutOfBoundsException extends Error {
/**
* Creates an IndexOutOfBoundsException
*
* @param {number} index the index that was attempted to be retrieved
*/
constructor(index) {
if (typeof index === 'undefined') {
throw new RequiredParameterException('index');
}
super(`The index ${index} is out of bounds.`);
}
}
/**
* A parameter was invalid.
*
* @extends {Error}
* @class
*/
class InvalidParameterException extends Error {
/**
* Creates an InvalidParameterException
*
* @param {string} paramName the parameter name that was invalid
* @param {string} reason the reason the parameter was invalid
*/
constructor(paramName, reason) {
if (typeof paramName === 'undefined') {
throw new RequiredParameterException('paramName');
}
if (typeof reason === 'undefined') {
throw new RequiredParameterException('reason');
}
super(`The parameter "${paramName}" was invalid. ${reason}`);
}
}
/**
* There were multiple items which matched the expression.
*
* @extends {Error}
* @class
*/
class MultipleItemsMatchException extends Error {
/**
* Creates a MultipleItemsMatchException
*/
constructor() {
super('There were multiple items which matched the expression');
}
}
/**
* There were no items which matched the expression.
*
* @extends {Error}
* @class
*/
class NoItemFoundException extends Error {
/**
* Creates a NoItemFoundException
*/
constructor() {
super('There were no items which matched the expression');
}
}
module.exports = {
IndexOutOfBoundsException: IndexOutOfBoundsException,
InvalidParameterException: InvalidParameterException,
MultipleItemsMatchException: MultipleItemsMatchException,
NoItemFoundException: NoItemFoundException,
RequiredParameterException: RequiredParameterException,
};