@api-client/core 0.12.10 → 0.12.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/src/browser.d.ts +0 -1
- package/build/src/browser.d.ts.map +1 -1
- package/build/src/browser.js +0 -1
- package/build/src/browser.js.map +1 -1
- package/build/src/exceptions/exception.d.ts +29 -1
- package/build/src/exceptions/exception.d.ts.map +1 -1
- package/build/src/exceptions/exception.js +37 -1
- package/build/src/exceptions/exception.js.map +1 -1
- package/build/src/index.d.ts +0 -1
- package/build/src/index.d.ts.map +1 -1
- package/build/src/index.js +0 -1
- package/build/src/index.js.map +1 -1
- package/build/src/models/store/Backend.d.ts +15 -2
- package/build/src/models/store/Backend.d.ts.map +1 -1
- package/build/src/models/store/Backend.js.map +1 -1
- package/build/src/proxy/HttpProjectProxy.d.ts.map +1 -1
- package/build/src/proxy/HttpProjectProxy.js +39 -43
- package/build/src/proxy/HttpProjectProxy.js.map +1 -1
- package/build/src/proxy/RequestProxy.d.ts.map +1 -1
- package/build/src/proxy/RequestProxy.js +11 -11
- package/build/src/proxy/RequestProxy.js.map +1 -1
- package/build/src/runtime/store/DataCatalogSdk.d.ts.map +1 -1
- package/build/src/runtime/store/DataCatalogSdk.js +49 -109
- package/build/src/runtime/store/DataCatalogSdk.js.map +1 -1
- package/build/src/runtime/store/FilesSdk.d.ts.map +1 -1
- package/build/src/runtime/store/FilesSdk.js +51 -115
- package/build/src/runtime/store/FilesSdk.js.map +1 -1
- package/build/src/runtime/store/HistorySdk.d.ts.map +1 -1
- package/build/src/runtime/store/HistorySdk.js +25 -70
- package/build/src/runtime/store/HistorySdk.js.map +1 -1
- package/build/src/runtime/store/OrganizationsSdk.d.ts.map +1 -1
- package/build/src/runtime/store/OrganizationsSdk.js +46 -50
- package/build/src/runtime/store/OrganizationsSdk.js.map +1 -1
- package/build/src/runtime/store/RevisionsSdk.d.ts.map +1 -1
- package/build/src/runtime/store/RevisionsSdk.js +5 -10
- package/build/src/runtime/store/RevisionsSdk.js.map +1 -1
- package/build/src/runtime/store/SdkBase.d.ts +7 -5
- package/build/src/runtime/store/SdkBase.d.ts.map +1 -1
- package/build/src/runtime/store/SdkBase.js +45 -63
- package/build/src/runtime/store/SdkBase.js.map +1 -1
- package/build/src/runtime/store/SharedSdk.d.ts.map +1 -1
- package/build/src/runtime/store/SharedSdk.js +5 -14
- package/build/src/runtime/store/SharedSdk.js.map +1 -1
- package/build/src/runtime/store/TrashSdk.d.ts.map +1 -1
- package/build/src/runtime/store/TrashSdk.js +8 -28
- package/build/src/runtime/store/TrashSdk.js.map +1 -1
- package/build/src/runtime/store/UsersSdk.d.ts.map +1 -1
- package/build/src/runtime/store/UsersSdk.js +12 -11
- package/build/src/runtime/store/UsersSdk.js.map +1 -1
- package/package.json +1 -1
- package/src/exceptions/exception.ts +51 -4
- package/src/models/store/Backend.ts +16 -2
- package/src/proxy/HttpProjectProxy.ts +39 -43
- package/src/proxy/RequestProxy.ts +11 -11
- package/src/runtime/store/DataCatalogSdk.ts +49 -109
- package/src/runtime/store/FilesSdk.ts +51 -115
- package/src/runtime/store/HistorySdk.ts +25 -70
- package/src/runtime/store/OrganizationsSdk.ts +46 -50
- package/src/runtime/store/RevisionsSdk.ts +5 -10
- package/src/runtime/store/SdkBase.ts +46 -65
- package/src/runtime/store/SharedSdk.ts +5 -14
- package/src/runtime/store/TrashSdk.ts +8 -28
- package/src/runtime/store/UsersSdk.ts +12 -11
- package/tests/unit/runtime/proxy/HttpProjectProxy.spec.ts +42 -40
- package/tests/unit/runtime/proxy/RequestProxy.spec.ts +11 -11
- package/build/src/runtime/store/Errors.d.ts +0 -51
- package/build/src/runtime/store/Errors.d.ts.map +0 -1
- package/build/src/runtime/store/Errors.js +0 -61
- package/build/src/runtime/store/Errors.js.map +0 -1
- package/src/runtime/store/Errors.ts +0 -98
|
@@ -10,9 +10,9 @@ import { RouteBuilder } from './RouteBuilder.js'
|
|
|
10
10
|
import type { ContextListOptions, ContextListResult } from '../../events/BaseEvents.js'
|
|
11
11
|
import type { IOrganization, UserOrganizationGrantType } from '../../models/store/Organization.js'
|
|
12
12
|
import type { InvitationSchema } from '../../models/store/Invitation.js'
|
|
13
|
-
import { SdkError } from './Errors.js'
|
|
14
13
|
import type { PatchInfo } from '../../patch/types.js'
|
|
15
14
|
import type { IUser } from '../../models/store/User.js'
|
|
15
|
+
import { Exception } from '../../exceptions/exception.js'
|
|
16
16
|
|
|
17
17
|
export class OrganizationsSdk extends SdkBase {
|
|
18
18
|
/**
|
|
@@ -26,24 +26,19 @@ export class OrganizationsSdk extends SdkBase {
|
|
|
26
26
|
const E_PREFIX = 'Unable to list your organizations. '
|
|
27
27
|
if (result.status !== 200) {
|
|
28
28
|
this.logInvalidResponse(result)
|
|
29
|
-
|
|
30
|
-
if (!e) {
|
|
31
|
-
e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)
|
|
32
|
-
e.response = result.body
|
|
33
|
-
}
|
|
34
|
-
throw e
|
|
29
|
+
throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
|
|
35
30
|
}
|
|
36
31
|
if (!result.body) {
|
|
37
|
-
throw new
|
|
32
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
|
|
38
33
|
}
|
|
39
34
|
let data: ContextListResult<IOrganization>
|
|
40
35
|
try {
|
|
41
36
|
data = JSON.parse(result.body)
|
|
42
37
|
} catch {
|
|
43
|
-
throw new
|
|
38
|
+
throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
|
|
44
39
|
}
|
|
45
40
|
if (!Array.isArray(data.items)) {
|
|
46
|
-
throw new
|
|
41
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
|
|
47
42
|
}
|
|
48
43
|
return data
|
|
49
44
|
}
|
|
@@ -64,19 +59,20 @@ export class OrganizationsSdk extends SdkBase {
|
|
|
64
59
|
this.inspectCommonStatusCodes(result)
|
|
65
60
|
const E_PREFIX = 'Unable to create an organization. '
|
|
66
61
|
if (result.status !== 200) {
|
|
67
|
-
|
|
62
|
+
this.logInvalidResponse(result)
|
|
63
|
+
throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
|
|
68
64
|
}
|
|
69
65
|
if (!result.body) {
|
|
70
|
-
throw new
|
|
66
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
|
|
71
67
|
}
|
|
72
68
|
let data: IOrganization
|
|
73
69
|
try {
|
|
74
70
|
data = JSON.parse(result.body)
|
|
75
71
|
} catch {
|
|
76
|
-
throw new
|
|
72
|
+
throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
|
|
77
73
|
}
|
|
78
74
|
if (!data.kind) {
|
|
79
|
-
throw new
|
|
75
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
|
|
80
76
|
}
|
|
81
77
|
return data
|
|
82
78
|
}
|
|
@@ -95,24 +91,19 @@ export class OrganizationsSdk extends SdkBase {
|
|
|
95
91
|
const E_PREFIX = 'Unable to list organization invitations. '
|
|
96
92
|
if (result.status !== 200) {
|
|
97
93
|
this.logInvalidResponse(result)
|
|
98
|
-
|
|
99
|
-
if (!e) {
|
|
100
|
-
e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)
|
|
101
|
-
e.response = result.body
|
|
102
|
-
}
|
|
103
|
-
throw e
|
|
94
|
+
throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
|
|
104
95
|
}
|
|
105
96
|
if (!result.body) {
|
|
106
|
-
throw new
|
|
97
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
|
|
107
98
|
}
|
|
108
99
|
let data: ContextListResult<InvitationSchema>
|
|
109
100
|
try {
|
|
110
101
|
data = JSON.parse(result.body)
|
|
111
102
|
} catch {
|
|
112
|
-
throw new
|
|
103
|
+
throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
|
|
113
104
|
}
|
|
114
105
|
if (!Array.isArray(data.items)) {
|
|
115
|
-
throw new
|
|
106
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
|
|
116
107
|
}
|
|
117
108
|
return data
|
|
118
109
|
}
|
|
@@ -149,19 +140,20 @@ export class OrganizationsSdk extends SdkBase {
|
|
|
149
140
|
this.inspectCommonStatusCodes(result)
|
|
150
141
|
const E_PREFIX = 'Unable to create an invitation. '
|
|
151
142
|
if (result.status !== 200) {
|
|
152
|
-
|
|
143
|
+
this.logInvalidResponse(result)
|
|
144
|
+
throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
|
|
153
145
|
}
|
|
154
146
|
if (!result.body) {
|
|
155
|
-
throw new
|
|
147
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
|
|
156
148
|
}
|
|
157
149
|
let data: InvitationSchema
|
|
158
150
|
try {
|
|
159
151
|
data = JSON.parse(result.body)
|
|
160
152
|
} catch {
|
|
161
|
-
throw new
|
|
153
|
+
throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
|
|
162
154
|
}
|
|
163
155
|
if (!data.kind) {
|
|
164
|
-
throw new
|
|
156
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
|
|
165
157
|
}
|
|
166
158
|
return data
|
|
167
159
|
}
|
|
@@ -180,19 +172,20 @@ export class OrganizationsSdk extends SdkBase {
|
|
|
180
172
|
this.inspectCommonStatusCodes(result)
|
|
181
173
|
const E_PREFIX = 'Unable to find invitation by token. '
|
|
182
174
|
if (result.status !== 200) {
|
|
183
|
-
|
|
175
|
+
this.logInvalidResponse(result)
|
|
176
|
+
throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
|
|
184
177
|
}
|
|
185
178
|
if (!result.body) {
|
|
186
|
-
throw new
|
|
179
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
|
|
187
180
|
}
|
|
188
181
|
let data: InvitationSchema
|
|
189
182
|
try {
|
|
190
183
|
data = JSON.parse(result.body)
|
|
191
184
|
} catch {
|
|
192
|
-
throw new
|
|
185
|
+
throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
|
|
193
186
|
}
|
|
194
187
|
if (!data.kind) {
|
|
195
|
-
throw new
|
|
188
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
|
|
196
189
|
}
|
|
197
190
|
return data
|
|
198
191
|
}
|
|
@@ -210,19 +203,20 @@ export class OrganizationsSdk extends SdkBase {
|
|
|
210
203
|
this.inspectCommonStatusCodes(result)
|
|
211
204
|
const E_PREFIX = 'Unable to decline invitation. '
|
|
212
205
|
if (result.status !== 200) {
|
|
213
|
-
|
|
206
|
+
this.logInvalidResponse(result)
|
|
207
|
+
throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
|
|
214
208
|
}
|
|
215
209
|
if (!result.body) {
|
|
216
|
-
throw new
|
|
210
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
|
|
217
211
|
}
|
|
218
212
|
let data: InvitationSchema
|
|
219
213
|
try {
|
|
220
214
|
data = JSON.parse(result.body)
|
|
221
215
|
} catch {
|
|
222
|
-
throw new
|
|
216
|
+
throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
|
|
223
217
|
}
|
|
224
218
|
if (!data.kind) {
|
|
225
|
-
throw new
|
|
219
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
|
|
226
220
|
}
|
|
227
221
|
return data
|
|
228
222
|
}
|
|
@@ -240,19 +234,20 @@ export class OrganizationsSdk extends SdkBase {
|
|
|
240
234
|
this.inspectCommonStatusCodes(result)
|
|
241
235
|
const E_PREFIX = 'Unable to delete invitation. '
|
|
242
236
|
if (result.status !== 200) {
|
|
243
|
-
|
|
237
|
+
this.logInvalidResponse(result)
|
|
238
|
+
throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
|
|
244
239
|
}
|
|
245
240
|
if (!result.body) {
|
|
246
|
-
throw new
|
|
241
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
|
|
247
242
|
}
|
|
248
243
|
let data: InvitationSchema
|
|
249
244
|
try {
|
|
250
245
|
data = JSON.parse(result.body)
|
|
251
246
|
} catch {
|
|
252
|
-
throw new
|
|
247
|
+
throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
|
|
253
248
|
}
|
|
254
249
|
if (!data.kind) {
|
|
255
|
-
throw new
|
|
250
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
|
|
256
251
|
}
|
|
257
252
|
return data
|
|
258
253
|
}
|
|
@@ -281,19 +276,20 @@ export class OrganizationsSdk extends SdkBase {
|
|
|
281
276
|
this.inspectCommonStatusCodes(result)
|
|
282
277
|
const E_PREFIX = 'Unable to update invitation. '
|
|
283
278
|
if (result.status !== 200) {
|
|
284
|
-
|
|
279
|
+
this.logInvalidResponse(result)
|
|
280
|
+
throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
|
|
285
281
|
}
|
|
286
282
|
if (!result.body) {
|
|
287
|
-
throw new
|
|
283
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
|
|
288
284
|
}
|
|
289
285
|
let data: InvitationSchema
|
|
290
286
|
try {
|
|
291
287
|
data = JSON.parse(result.body)
|
|
292
288
|
} catch {
|
|
293
|
-
throw new
|
|
289
|
+
throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
|
|
294
290
|
}
|
|
295
291
|
if (!data.kind) {
|
|
296
|
-
throw new
|
|
292
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
|
|
297
293
|
}
|
|
298
294
|
return data
|
|
299
295
|
}
|
|
@@ -318,19 +314,19 @@ export class OrganizationsSdk extends SdkBase {
|
|
|
318
314
|
const E_PREFIX = 'Unable to list projects. '
|
|
319
315
|
if (result.status !== 200) {
|
|
320
316
|
this.logInvalidResponse(result)
|
|
321
|
-
throw
|
|
317
|
+
throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
|
|
322
318
|
}
|
|
323
319
|
if (!result.body) {
|
|
324
|
-
throw new
|
|
320
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
|
|
325
321
|
}
|
|
326
322
|
let data: ContextListResult<IUser>
|
|
327
323
|
try {
|
|
328
324
|
data = JSON.parse(result.body)
|
|
329
325
|
} catch {
|
|
330
|
-
throw new
|
|
326
|
+
throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
|
|
331
327
|
}
|
|
332
328
|
if (!Array.isArray(data.items)) {
|
|
333
|
-
throw new
|
|
329
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
|
|
334
330
|
}
|
|
335
331
|
return data
|
|
336
332
|
}
|
|
@@ -352,16 +348,16 @@ export class OrganizationsSdk extends SdkBase {
|
|
|
352
348
|
const E_PREFIX = 'Unable to read the user info. '
|
|
353
349
|
if (result.status !== 200) {
|
|
354
350
|
this.logInvalidResponse(result)
|
|
355
|
-
throw
|
|
351
|
+
throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
|
|
356
352
|
}
|
|
357
353
|
if (!result.body) {
|
|
358
|
-
throw new
|
|
354
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
|
|
359
355
|
}
|
|
360
356
|
let data: IUser
|
|
361
357
|
try {
|
|
362
358
|
data = JSON.parse(result.body)
|
|
363
359
|
} catch {
|
|
364
|
-
throw new
|
|
360
|
+
throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
|
|
365
361
|
}
|
|
366
362
|
return data
|
|
367
363
|
}
|
|
@@ -8,8 +8,8 @@ import {
|
|
|
8
8
|
} from './SdkBase.js'
|
|
9
9
|
import { RouteBuilder } from './RouteBuilder.js'
|
|
10
10
|
import type { ContextListResult, ContextListOptions } from '../../events/BaseEvents.js'
|
|
11
|
-
import { SdkError } from './Errors.js'
|
|
12
11
|
import type { IRevision } from '../../models/store/Revision.js'
|
|
12
|
+
import { Exception } from '../../exceptions/exception.js'
|
|
13
13
|
|
|
14
14
|
export class RevisionsSdk extends SdkBase {
|
|
15
15
|
/**
|
|
@@ -32,24 +32,19 @@ export class RevisionsSdk extends SdkBase {
|
|
|
32
32
|
const E_PREFIX = 'Unable to list revisions for a file. '
|
|
33
33
|
if (result.status !== 200) {
|
|
34
34
|
this.logInvalidResponse(result)
|
|
35
|
-
|
|
36
|
-
if (!e) {
|
|
37
|
-
e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)
|
|
38
|
-
e.response = result.body
|
|
39
|
-
}
|
|
40
|
-
throw e
|
|
35
|
+
throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
|
|
41
36
|
}
|
|
42
37
|
if (!result.body) {
|
|
43
|
-
throw new
|
|
38
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
|
|
44
39
|
}
|
|
45
40
|
let data: ContextListResult<IRevision>
|
|
46
41
|
try {
|
|
47
42
|
data = JSON.parse(result.body)
|
|
48
43
|
} catch {
|
|
49
|
-
throw new
|
|
44
|
+
throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
|
|
50
45
|
}
|
|
51
46
|
if (!Array.isArray(data.items)) {
|
|
52
|
-
throw new
|
|
47
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
|
|
53
48
|
}
|
|
54
49
|
return data
|
|
55
50
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
2
|
import { Headers } from '../../lib/headers/Headers.js'
|
|
3
3
|
import { Sdk } from './Sdk.js'
|
|
4
|
-
import { SdkError, IApiError } from './Errors.js'
|
|
5
4
|
import {
|
|
6
5
|
ContextDeleteRecord,
|
|
7
6
|
ContextListOptions,
|
|
8
7
|
ContextListResult,
|
|
9
8
|
IBulkOperationResult,
|
|
10
9
|
} from '../../events/BaseEvents.js'
|
|
10
|
+
import { Exception } from '../../exceptions/exception.js'
|
|
11
11
|
|
|
12
12
|
export interface SdkOptions {
|
|
13
13
|
/**
|
|
@@ -65,61 +65,59 @@ export class SdkBase {
|
|
|
65
65
|
protected inspectCommonStatusCodes(response: IStoreResponse): void {
|
|
66
66
|
const { status, body } = response
|
|
67
67
|
if (status === 404) {
|
|
68
|
-
|
|
69
|
-
if (
|
|
70
|
-
e
|
|
71
|
-
|
|
68
|
+
const e = this.createApiError('Not found', body)
|
|
69
|
+
if (e.status !== 404) {
|
|
70
|
+
e.setStatus(404)
|
|
71
|
+
}
|
|
72
|
+
if (e.code !== 'E_NOT_FOUND') {
|
|
73
|
+
e.setCode('E_NOT_FOUND')
|
|
72
74
|
}
|
|
73
75
|
throw e
|
|
74
76
|
}
|
|
75
77
|
if (status === 403) {
|
|
76
|
-
|
|
77
|
-
if (
|
|
78
|
-
e
|
|
79
|
-
|
|
78
|
+
const e = this.createApiError('You have no access to this resource', body)
|
|
79
|
+
if (e.status !== 403) {
|
|
80
|
+
e.setStatus(403)
|
|
81
|
+
}
|
|
82
|
+
if (e.code !== 'E_FORBIDDEN') {
|
|
83
|
+
e.setCode('E_FORBIDDEN')
|
|
80
84
|
}
|
|
81
85
|
throw e
|
|
82
86
|
}
|
|
83
87
|
if (status === 401) {
|
|
84
|
-
|
|
85
|
-
if (
|
|
86
|
-
e
|
|
87
|
-
|
|
88
|
+
const e = this.createApiError('Not authorized', body)
|
|
89
|
+
if (e.status !== 401) {
|
|
90
|
+
e.setStatus(401)
|
|
91
|
+
}
|
|
92
|
+
if (e.code !== 'E_UNAUTHORIZED') {
|
|
93
|
+
e.setCode('E_UNAUTHORIZED')
|
|
88
94
|
}
|
|
89
95
|
throw e
|
|
90
96
|
}
|
|
91
97
|
}
|
|
92
98
|
|
|
93
99
|
/**
|
|
94
|
-
*
|
|
100
|
+
* Creates an Exception from the response body.
|
|
101
|
+
* It reads the error details from the body.
|
|
102
|
+
*
|
|
103
|
+
* @param defaultMessage The default message to use if the body does not contain a message.
|
|
95
104
|
* @param body The message returned by the store.
|
|
96
|
-
* @returns The
|
|
105
|
+
* @returns The Exception or undefined when not an error.
|
|
97
106
|
*/
|
|
98
|
-
protected
|
|
107
|
+
protected createApiError(defaultMessage: string, body?: string): Exception {
|
|
99
108
|
if (!body) {
|
|
100
|
-
return
|
|
109
|
+
return new Exception(defaultMessage)
|
|
101
110
|
}
|
|
102
|
-
let data:
|
|
111
|
+
let data: Record<string, string | number>
|
|
103
112
|
try {
|
|
104
113
|
data = JSON.parse(body)
|
|
105
114
|
} catch {
|
|
106
|
-
return
|
|
115
|
+
return new Exception(defaultMessage)
|
|
107
116
|
}
|
|
108
|
-
if (data
|
|
109
|
-
return
|
|
117
|
+
if (!data || typeof data !== 'object' || !data.message) {
|
|
118
|
+
return new Exception(defaultMessage)
|
|
110
119
|
}
|
|
111
|
-
return
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
protected createGenericSdkError(body?: string): SdkError | undefined {
|
|
115
|
-
const info = this.readErrorResponse(body)
|
|
116
|
-
if (!info) {
|
|
117
|
-
return undefined
|
|
118
|
-
}
|
|
119
|
-
const e = new SdkError(info.message, info.code)
|
|
120
|
-
e.detail = info.detail
|
|
121
|
-
e.response = body
|
|
122
|
-
return e
|
|
120
|
+
return Exception.fromRawException(data, defaultMessage)
|
|
123
121
|
}
|
|
124
122
|
|
|
125
123
|
/**
|
|
@@ -141,25 +139,20 @@ export class SdkBase {
|
|
|
141
139
|
const E_PREFIX = 'Unable to delete in batch. '
|
|
142
140
|
if (result.status !== 200) {
|
|
143
141
|
this.logInvalidResponse(result)
|
|
144
|
-
|
|
145
|
-
if (!e) {
|
|
146
|
-
e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)
|
|
147
|
-
e.response = result.body
|
|
148
|
-
}
|
|
149
|
-
throw e
|
|
142
|
+
throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
|
|
150
143
|
}
|
|
151
144
|
if (!result.body) {
|
|
152
|
-
throw new
|
|
145
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
|
|
153
146
|
}
|
|
154
147
|
|
|
155
148
|
let data: IBulkOperationResult<ContextDeleteRecord>
|
|
156
149
|
try {
|
|
157
150
|
data = JSON.parse(result.body)
|
|
158
151
|
} catch {
|
|
159
|
-
throw new
|
|
152
|
+
throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
|
|
160
153
|
}
|
|
161
154
|
if (!Array.isArray(data.items)) {
|
|
162
|
-
throw new
|
|
155
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
|
|
163
156
|
}
|
|
164
157
|
return data
|
|
165
158
|
}
|
|
@@ -177,12 +170,7 @@ export class SdkBase {
|
|
|
177
170
|
const E_PREFIX = 'Unable to delete the object. '
|
|
178
171
|
if (result.status !== 204) {
|
|
179
172
|
this.logInvalidResponse(result)
|
|
180
|
-
|
|
181
|
-
if (!e) {
|
|
182
|
-
e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)
|
|
183
|
-
e.response = result.body
|
|
184
|
-
}
|
|
185
|
-
throw e
|
|
173
|
+
throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
|
|
186
174
|
}
|
|
187
175
|
}
|
|
188
176
|
|
|
@@ -198,24 +186,19 @@ export class SdkBase {
|
|
|
198
186
|
const E_PREFIX = 'Unable to list revisions for a file. '
|
|
199
187
|
if (result.status !== 200) {
|
|
200
188
|
this.logInvalidResponse(result)
|
|
201
|
-
|
|
202
|
-
if (!e) {
|
|
203
|
-
e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)
|
|
204
|
-
e.response = result.body
|
|
205
|
-
}
|
|
206
|
-
throw e
|
|
189
|
+
throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
|
|
207
190
|
}
|
|
208
191
|
if (!result.body) {
|
|
209
|
-
throw new
|
|
192
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
|
|
210
193
|
}
|
|
211
194
|
let data: ContextListResult<unknown>
|
|
212
195
|
try {
|
|
213
196
|
data = JSON.parse(result.body)
|
|
214
197
|
} catch {
|
|
215
|
-
throw new
|
|
198
|
+
throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
|
|
216
199
|
}
|
|
217
200
|
if (!Array.isArray(data.items)) {
|
|
218
|
-
throw new
|
|
201
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
|
|
219
202
|
}
|
|
220
203
|
return data
|
|
221
204
|
}
|
|
@@ -223,15 +206,13 @@ export class SdkBase {
|
|
|
223
206
|
protected readResponseBody(response: IStoreResponse, errorPrefix: string): string {
|
|
224
207
|
if (response.status !== 200) {
|
|
225
208
|
this.logInvalidResponse(response)
|
|
226
|
-
|
|
227
|
-
if (!e) {
|
|
228
|
-
e = new SdkError(`${errorPrefix}${E_RESPONSE_STATUS}${response.status}`, response.status)
|
|
229
|
-
e.response = response.body
|
|
230
|
-
}
|
|
231
|
-
throw e
|
|
209
|
+
throw this.createApiError(`${errorPrefix}${E_RESPONSE_STATUS}${response.status}`, response.body)
|
|
232
210
|
}
|
|
233
211
|
if (!response.body) {
|
|
234
|
-
throw new
|
|
212
|
+
throw new Exception(`${errorPrefix}${E_RESPONSE_NO_VALUE}`, {
|
|
213
|
+
code: 'E_RESPONSE_NO_VALUE',
|
|
214
|
+
status: response.status,
|
|
215
|
+
})
|
|
235
216
|
}
|
|
236
217
|
return response.body
|
|
237
218
|
}
|
|
@@ -242,7 +223,7 @@ export class SdkBase {
|
|
|
242
223
|
try {
|
|
243
224
|
data = JSON.parse(body)
|
|
244
225
|
} catch {
|
|
245
|
-
throw new
|
|
226
|
+
throw new Exception(`${errorPrefix}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: response.status })
|
|
246
227
|
}
|
|
247
228
|
return data
|
|
248
229
|
}
|
|
@@ -8,9 +8,9 @@ import {
|
|
|
8
8
|
} from './SdkBase.js'
|
|
9
9
|
import { RouteBuilder } from './RouteBuilder.js'
|
|
10
10
|
import { IFile } from '../../models/store/File.js'
|
|
11
|
-
import { SdkError } from './Errors.js'
|
|
12
11
|
import { ListFileKind } from './FilesSdk.js'
|
|
13
12
|
import { ContextListOptions, ContextListResult } from '../../events/BaseEvents.js'
|
|
13
|
+
import { Exception } from '../../exceptions/exception.js'
|
|
14
14
|
|
|
15
15
|
export class SharedSdk extends SdkBase {
|
|
16
16
|
/**
|
|
@@ -37,28 +37,19 @@ export class SharedSdk extends SdkBase {
|
|
|
37
37
|
const E_PREFIX = 'Unable to list organizations. '
|
|
38
38
|
if (result.status !== 200) {
|
|
39
39
|
this.logInvalidResponse(result)
|
|
40
|
-
|
|
41
|
-
if (!e) {
|
|
42
|
-
e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)
|
|
43
|
-
e.response = result.body
|
|
44
|
-
}
|
|
45
|
-
throw e
|
|
40
|
+
throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
|
|
46
41
|
}
|
|
47
42
|
if (!result.body) {
|
|
48
|
-
throw new
|
|
43
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
|
|
49
44
|
}
|
|
50
45
|
let data: ContextListResult<IFile>
|
|
51
46
|
try {
|
|
52
47
|
data = JSON.parse(result.body)
|
|
53
48
|
} catch {
|
|
54
|
-
|
|
55
|
-
err.response = result.body
|
|
56
|
-
throw err
|
|
49
|
+
throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
|
|
57
50
|
}
|
|
58
51
|
if (!Array.isArray(data.items)) {
|
|
59
|
-
|
|
60
|
-
err.response = result.body
|
|
61
|
-
throw err
|
|
52
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
|
|
62
53
|
}
|
|
63
54
|
return data
|
|
64
55
|
}
|
|
@@ -8,8 +8,8 @@ import {
|
|
|
8
8
|
} from './SdkBase.js'
|
|
9
9
|
import { RouteBuilder } from './RouteBuilder.js'
|
|
10
10
|
import type { ContextListOptions, ContextListResult } from '../../events/BaseEvents.js'
|
|
11
|
-
import { SdkError } from './Errors.js'
|
|
12
11
|
import type { TrashEntry } from '../../models/TrashEntry.js'
|
|
12
|
+
import { Exception } from '../../exceptions/exception.js'
|
|
13
13
|
|
|
14
14
|
export class TrashSdk extends SdkBase {
|
|
15
15
|
/**
|
|
@@ -29,24 +29,19 @@ export class TrashSdk extends SdkBase {
|
|
|
29
29
|
const E_PREFIX = 'Unable to list trash. '
|
|
30
30
|
if (result.status !== 200) {
|
|
31
31
|
this.logInvalidResponse(result)
|
|
32
|
-
|
|
33
|
-
if (!e) {
|
|
34
|
-
e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)
|
|
35
|
-
e.response = result.body
|
|
36
|
-
}
|
|
37
|
-
throw e
|
|
32
|
+
throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
|
|
38
33
|
}
|
|
39
34
|
if (!result.body) {
|
|
40
|
-
throw new
|
|
35
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
|
|
41
36
|
}
|
|
42
37
|
let data: ContextListResult<TrashEntry>
|
|
43
38
|
try {
|
|
44
39
|
data = JSON.parse(result.body)
|
|
45
40
|
} catch {
|
|
46
|
-
throw new
|
|
41
|
+
throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
|
|
47
42
|
}
|
|
48
43
|
if (!Array.isArray(data.items)) {
|
|
49
|
-
throw new
|
|
44
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
|
|
50
45
|
}
|
|
51
46
|
return data
|
|
52
47
|
}
|
|
@@ -67,12 +62,7 @@ export class TrashSdk extends SdkBase {
|
|
|
67
62
|
const E_PREFIX = 'Unable to delete trash. '
|
|
68
63
|
if (result.status !== 204) {
|
|
69
64
|
this.logInvalidResponse(result)
|
|
70
|
-
|
|
71
|
-
if (!e) {
|
|
72
|
-
e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)
|
|
73
|
-
e.response = result.body
|
|
74
|
-
}
|
|
75
|
-
throw e
|
|
65
|
+
throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
|
|
76
66
|
}
|
|
77
67
|
}
|
|
78
68
|
|
|
@@ -84,12 +74,7 @@ export class TrashSdk extends SdkBase {
|
|
|
84
74
|
const E_PREFIX = 'Unable to restore from trash. '
|
|
85
75
|
if (result.status !== 204) {
|
|
86
76
|
this.logInvalidResponse(result)
|
|
87
|
-
|
|
88
|
-
if (!e) {
|
|
89
|
-
e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)
|
|
90
|
-
e.response = result.body
|
|
91
|
-
}
|
|
92
|
-
throw e
|
|
77
|
+
throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
|
|
93
78
|
}
|
|
94
79
|
}
|
|
95
80
|
|
|
@@ -105,12 +90,7 @@ export class TrashSdk extends SdkBase {
|
|
|
105
90
|
const E_PREFIX = 'Unable to empty trash. '
|
|
106
91
|
if (result.status !== 204) {
|
|
107
92
|
this.logInvalidResponse(result)
|
|
108
|
-
|
|
109
|
-
if (!e) {
|
|
110
|
-
e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)
|
|
111
|
-
e.response = result.body
|
|
112
|
-
}
|
|
113
|
-
throw e
|
|
93
|
+
throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
|
|
114
94
|
}
|
|
115
95
|
}
|
|
116
96
|
}
|