-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherrors.js
More file actions
86 lines (76 loc) · 2.17 KB
/
errors.js
File metadata and controls
86 lines (76 loc) · 2.17 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
const AccountErrorEnum = Object.freeze({
FAILED_AUTHENTICATION: "Failed to authenticate",
MAX_ATTEMPTS: "Maximum authentication attempts exceeded",
});
const SessionErrorEnum = Object.freeze({
NOT_FOUND: "Session ID not found",
INVALID: "Session not active or timed out",
});
const ArgumentErrorEnum = Object.freeze({
MINUTES_INVALID: "Minutes must be an integer between 1 and 1440",
MAX_COUNT_INVALID: "Max count must be an integer between 1 and 288",
USERNAME_INVALID: "Username must be non-empty string",
USER_ID_MULTIPLE: "Only one of accountId, username should be provided",
USER_ID_REQUIRED: "At least one of accountId, username should be provided",
PASSWORD_INVALID: "Password must be non-empty string",
REGION_INVALID: "Region must be 'us', 'ous', or 'jp'",
ACCOUNT_ID_INVALID: "Account ID must be UUID",
ACCOUNT_ID_DEFAULT: "Account ID default",
SESSION_ID_INVALID: "Session ID must be UUID",
SESSION_ID_DEFAULT: "Session ID default",
GLUCOSE_READING_INVALID: "JSON glucose reading incorrectly formatted",
});
const ServerErrorEnum = Object.freeze({
INVALID_JSON: "Invalid or malformed JSON in server response",
UNKNOWN_CODE: "Unknown error code in server response",
UNEXPECTED: "Unexpected server response",
});
class DexcomError extends Error {
constructor(errorEnum = null) {
if (errorEnum !== null) {
super(errorEnum);
} else {
super();
}
this.name = "DexcomError";
this._enum = errorEnum;
}
get enum() {
return this._enum;
}
}
class AccountError extends DexcomError {
constructor(errorEnum) {
super(errorEnum);
this.name = "AccountError";
}
}
class SessionError extends DexcomError {
constructor(errorEnum) {
super(errorEnum);
this.name = "SessionError";
}
}
class ArgumentError extends DexcomError {
constructor(errorEnum) {
super(errorEnum);
this.name = "ArgumentError";
}
}
class ServerError extends DexcomError {
constructor(errorEnum) {
super(errorEnum);
this.name = "ServerError";
}
}
module.exports = {
AccountErrorEnum,
SessionErrorEnum,
ArgumentErrorEnum,
ServerErrorEnum,
DexcomError,
AccountError,
SessionError,
ArgumentError,
ServerError,
};