-
Notifications
You must be signed in to change notification settings - Fork 547
/
Copy pathRestError.js
233 lines (189 loc) · 5.47 KB
/
RestError.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
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
// @flow
//@bundleInto:common-min
import {TutanotaError} from "./TutanotaError"
export class ConnectionError extends TutanotaError {
static CODE: number = 0
constructor(msg: string) {
super("ConnectionError", msg)
}
}
export class BadRequestError extends TutanotaError {
static CODE: number = 400
constructor(msg: string) {
super("BadRequestError", msg)
}
}
export class NotAuthenticatedError extends TutanotaError {
static CODE: number = 401
constructor(msg: string) {
super("NotAuthenticatedError", msg)
}
}
export class NotAuthorizedError extends TutanotaError {
static CODE: number = 403
constructor(msg: string) {
super("NotAuthorizedError", msg)
}
}
export class NotFoundError extends TutanotaError {
static CODE: number = 404
constructor(msg: string) {
super("NotFoundError", msg)
}
}
export class MethodNotAllowedError extends TutanotaError {
static CODE: number = 405
constructor(msg: string) {
super("MethodNotAllowedError", msg)
}
}
export class PreconditionFailedError extends TutanotaError {
static CODE: number = 412
// data field is respected by the WorkerProtocol. Other fields might not be passed
data: ?string;
constructor(msg: string, reason: ?string) {
super("PreconditionFailedError", msg)
this.data = reason
}
}
export class LockedError extends TutanotaError {
static CODE: number = 423
constructor(msg: string) {
super("LockedError", msg)
}
}
export class TooManyRequestsError extends TutanotaError {
static CODE: number = 429
constructor(msg: string) {
super("TooManyRequestsError", msg)
}
}
export class SessionExpiredError extends TutanotaError {
static CODE: number = 440
constructor(msg: string) {
super("SessionExpiredError", msg)
}
}
export class AccessDeactivatedError extends TutanotaError {
static CODE: number = 470
constructor(msg: string) {
super("AccessDeactivatedError", msg)
}
}
export class AccessExpiredError extends TutanotaError {
static CODE: number = 471
constructor(msg: string) {
super("AccessExpiredError", msg)
}
}
export class AccessBlockedError extends TutanotaError {
static CODE: number = 472
constructor(msg: string) {
super("AccessBlockedError", msg)
}
}
export class InvalidDataError extends TutanotaError {
static CODE: number = 473
constructor(msg: string) {
super("InvalidDataError", msg)
}
}
export class InvalidSoftwareVersionError extends TutanotaError {
static CODE: number = 474
constructor(msg: string) {
super("InvalidSoftwareVersionError", msg)
}
}
export class LimitReachedError extends TutanotaError {
static CODE: number = 475
constructor(msg: string) {
super("LimitReachedError", msg)
}
}
export class InternalServerError extends TutanotaError {
static CODE: number = 500
constructor(msg: string) {
super("InternalServerError", msg)
}
}
export class BadGatewayError extends TutanotaError {
static CODE: number = 502
constructor(msg: string) {
super("BadGatewayError", msg)
}
}
export class ServiceUnavailableError extends TutanotaError {
static CODE: number = 503
constructor(msg: string) {
super("ServiceUnavailableError", msg)
}
}
export class InsufficientStorageError extends TutanotaError {
static CODE: number = 507
constructor(msg: string) {
super("InsufficientStorageError", msg)
}
}
export class ResourceError extends TutanotaError {
constructor(msg: string) {
super("ResourceError", msg)
}
}
export class PayloadTooLargeError extends TutanotaError {
static CODE: number = 413
constructor(msg: string) {
super("PayloadTooLargeError", msg)
}
}
/**
* Attention: When adding an Error also add it in WorkerProtocol.ErrorNameToType.
*/
export function handleRestError(errorCode: number, path: string, errorId: ?string, precondition: ?string): TutanotaError {
let message = `${errorCode}: ${errorId ? (errorId + " ") : ""}${precondition ? (precondition + " ") : ""}${path}`
switch (errorCode) {
case ConnectionError.CODE:
return new ConnectionError(message);
case BadRequestError.CODE:
return new BadRequestError(message);
case NotAuthenticatedError.CODE:
return new NotAuthenticatedError(message);
case NotAuthorizedError.CODE:
return new NotAuthorizedError(message);
case NotFoundError.CODE:
return new NotFoundError(message);
case MethodNotAllowedError.CODE:
return new MethodNotAllowedError(message);
case PreconditionFailedError.CODE:
return new PreconditionFailedError(message, precondition);
case LockedError.CODE:
return new LockedError(message);
case TooManyRequestsError.CODE:
return new TooManyRequestsError(message);
case SessionExpiredError.CODE:
return new SessionExpiredError(message);
case AccessDeactivatedError.CODE:
return new AccessDeactivatedError(message);
case AccessExpiredError.CODE:
return new AccessExpiredError(message);
case AccessBlockedError.CODE:
return new AccessBlockedError(message);
case InvalidDataError.CODE:
return new InvalidDataError(message);
case InvalidSoftwareVersionError.CODE:
return new InvalidSoftwareVersionError(message);
case LimitReachedError.CODE:
return new LimitReachedError(message);
case InternalServerError.CODE:
return new InternalServerError(message);
case BadGatewayError.CODE:
return new BadGatewayError(message);
case ServiceUnavailableError.CODE:
return new ServiceUnavailableError(message);
case InsufficientStorageError.CODE:
return new InsufficientStorageError(message);
case PayloadTooLargeError.CODE:
return new PayloadTooLargeError(message);
default:
return new ResourceError(message);
}
}