-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.ts
More file actions
109 lines (99 loc) · 2.69 KB
/
Copy patherrors.ts
File metadata and controls
109 lines (99 loc) · 2.69 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
export class KeitoError extends Error {
constructor(message: string) {
super(message);
this.name = 'KeitoError';
}
}
export class KeitoApiError extends KeitoError {
readonly status: number;
readonly error: string;
readonly error_description: string;
readonly headers: Headers;
readonly body: Record<string, unknown> | null;
constructor(
status: number,
error: string,
error_description: string,
headers: Headers,
body: Record<string, unknown> | null = null,
) {
super(`${status} ${error}: ${error_description}`);
this.name = 'KeitoApiError';
this.status = status;
this.error = error;
this.error_description = error_description;
this.headers = headers;
this.body = body;
}
}
export class KeitoAuthError extends KeitoApiError {
constructor(
error: string,
error_description: string,
headers: Headers,
body: Record<string, unknown> | null = null,
) {
super(401, error, error_description, headers, body);
this.name = 'KeitoAuthError';
}
}
export class KeitoForbiddenError extends KeitoApiError {
constructor(
error: string,
error_description: string,
headers: Headers,
body: Record<string, unknown> | null = null,
) {
super(403, error, error_description, headers, body);
this.name = 'KeitoForbiddenError';
}
}
export class KeitoNotFoundError extends KeitoApiError {
constructor(
error: string,
error_description: string,
headers: Headers,
body: Record<string, unknown> | null = null,
) {
super(404, error, error_description, headers, body);
this.name = 'KeitoNotFoundError';
}
}
export class KeitoConflictError extends KeitoApiError {
constructor(
error: string,
error_description: string,
headers: Headers,
body: Record<string, unknown> | null = null,
) {
super(409, error, error_description, headers, body);
this.name = 'KeitoConflictError';
}
}
export class KeitoRateLimitError extends KeitoApiError {
readonly retryAfter: number | null;
constructor(
error: string,
error_description: string,
headers: Headers,
body: Record<string, unknown> | null = null,
) {
super(429, error, error_description, headers, body);
this.name = 'KeitoRateLimitError';
const ra = headers.get('retry-after');
this.retryAfter = ra ? parseInt(ra, 10) : null;
}
}
export class KeitoTimeoutError extends KeitoError {
constructor() {
super('Request timed out');
this.name = 'KeitoTimeoutError';
}
}
export class KeitoConnectionError extends KeitoError {
constructor(cause?: Error) {
super(`Connection error: ${cause?.message ?? 'unknown'}`);
this.name = 'KeitoConnectionError';
if (cause) this.cause = cause;
}
}