-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRandomOrgErrors.js
More file actions
179 lines (165 loc) · 5.09 KB
/
Copy pathRandomOrgErrors.js
File metadata and controls
179 lines (165 loc) · 5.09 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
'use strict';
/**
* Error thrown by the RandomOrgClient class when the connection doesn't return
* a HTTP 200 OK response.
*/
exports.RandomOrgBadHTTPResponseError = class RandomOrgBadHTTPResponseError extends Error
{
/**
* Constructs a new exception with the specified detail message.
* @param {string} message The detail message.
*/
constructor(message) {
super(message);
}
}
/**
* Error thrown by the RandomOrgClient class when its API key's request has
* exceeded its remaining server bits allowance.
*
* If the client is currently issuing large requests it may be possible succeed
* with smaller requests. Use the getBitsLeft() call in this class to help
* determine if an alternative request size is appropriate.
*/
exports.RandomOrgInsufficientBitsError = class RandomOrgInsufficientBitsError extends Error
{
// Stores the number of bits remaining
#bits = -1;
/**
* Constructs a new exception with the specified detail message.
* @constructor
* @param {string} message The detail message.
* @param {number} bits Bits remaining just before the error was thrown.
*/
constructor(message, bits) {
super(message);
this.#bits = bits;
}
/**
* Gets the number of bits remaining.
* @returns {number} The number of bits left.
*/
getBitsLeft() {
return this.#bits;
}
}
/**
* Error thrown by the RandomOrgClient class when its API key's server requests
* allowance has been exceeded.
*
* This indicates that a back-off until midnight UTC is in effect, before which
* no requests will be sent by the client as no meaningful server responses will
* be returned.
*/
exports.RandomOrgInsufficientRequestsError = class RandomOrgInsufficientRequestsError extends Error
{
/**
* Constructs a new exception with the specified detail message.
* @constructor
* @param {string} message The detail message.
*/
constructor(message) {
super(message);
}
}
/**
* Error thrown by the RandomOrgClient class when the server returns a JSON-RPC
* Error. See https://api.random.org/json-rpc/4/error-codes
*/
exports.RandomOrgJSONRPCError = class RandomOrgJSONRPCError extends Error
{
/**
* Constructs a new exception with the specified detail message.
* @constructor
* @param {string} message The detail message.
*/
constructor(message) {
super(message);
}
}
/**
* Error thrown by the RandomOrgClient class when its API key has been stopped.
* Requests will not complete while API key is in the stopped state.
*/
exports.RandomOrgKeyNotRunningError = class RandomOrgKeyNotRunningError extends Error
{
/**
* Error thrown by the RandomOrgClient class when its API key has been stopped.
* Requests will not complete while API key is in the stopped state.
* @constructor
* @param {string} message The detail message.
*/
constructor(message) {
super(message);
}
}
/**
* Error thrown by the RandomOrgClient class when the server returns a
* RANDOM.ORG Error. See https://api.random.org/json-rpc/4/error-codes
*/
exports.RandomOrgRANDOMORGError = class RandomOrgRANDOMORGError extends Error
{
// Stores the code of the RANDOM.ORG error
#code = -1;
/**
* Error thrown by the RandomOrgClient class when the server returns a
* RANDOM.ORG Error. See https://api.random.org/json-rpc/4/error-codes
* @constructor
* @param {string} message The detail message.
* @param {number=} [code=-1] The error code.
*/
constructor(message, code = -1) {
super(message);
this.#code = code;
}
/**
* Gets the RANDOM.ORG error code, see
* https://api.random.org/json-rpc/4/error-codes
* @returns {number} The error code.
*/
getCode() {
return this.#code;
}
}
/**
* Error thrown by the RandomOrgClient class when its set blocking timeout is
* exceeded before the request can be sent.
*/
exports.RandomOrgSendTimeoutError = class RandomOrgSendTimeoutError extends Error
{
/**
* Error thrown by the RandomOrgClient class when its set blocking timeout is
* exceeded before the request can be sent.
* @constructor
* @param {string} message The detail message.
*/
constructor(message) {
super(message);
}
}
/**
* Error thrown when data retrieval from an emtpy RandomOrgCache is attempted.
*/
exports.RandomOrgCacheEmptyError = class RandomOrgCacheEmptyError extends Error
{
#paused = false;
/**
* Error thrown when data retrieval from an emtpy RandomOrgCache is attempted.
* @constructor
* @param {string} message The detail message.
* @param {boolean} paused Reflects whether the RandomOrgCache instance was
* paused when this error was thrown.
*/
constructor(message, paused = false) {
super(message);
this.#paused = paused;
}
/**
* Returns whether the cache was paused at the time when the
* error was thrown.
* @returns {boolean} True if paused, false otherwise.
*/
wasPaused() {
return this.#paused;
}
}