@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.
Files changed (70) hide show
  1. package/build/src/browser.d.ts +0 -1
  2. package/build/src/browser.d.ts.map +1 -1
  3. package/build/src/browser.js +0 -1
  4. package/build/src/browser.js.map +1 -1
  5. package/build/src/exceptions/exception.d.ts +29 -1
  6. package/build/src/exceptions/exception.d.ts.map +1 -1
  7. package/build/src/exceptions/exception.js +37 -1
  8. package/build/src/exceptions/exception.js.map +1 -1
  9. package/build/src/index.d.ts +0 -1
  10. package/build/src/index.d.ts.map +1 -1
  11. package/build/src/index.js +0 -1
  12. package/build/src/index.js.map +1 -1
  13. package/build/src/models/store/Backend.d.ts +15 -2
  14. package/build/src/models/store/Backend.d.ts.map +1 -1
  15. package/build/src/models/store/Backend.js.map +1 -1
  16. package/build/src/proxy/HttpProjectProxy.d.ts.map +1 -1
  17. package/build/src/proxy/HttpProjectProxy.js +39 -43
  18. package/build/src/proxy/HttpProjectProxy.js.map +1 -1
  19. package/build/src/proxy/RequestProxy.d.ts.map +1 -1
  20. package/build/src/proxy/RequestProxy.js +11 -11
  21. package/build/src/proxy/RequestProxy.js.map +1 -1
  22. package/build/src/runtime/store/DataCatalogSdk.d.ts.map +1 -1
  23. package/build/src/runtime/store/DataCatalogSdk.js +49 -109
  24. package/build/src/runtime/store/DataCatalogSdk.js.map +1 -1
  25. package/build/src/runtime/store/FilesSdk.d.ts.map +1 -1
  26. package/build/src/runtime/store/FilesSdk.js +51 -115
  27. package/build/src/runtime/store/FilesSdk.js.map +1 -1
  28. package/build/src/runtime/store/HistorySdk.d.ts.map +1 -1
  29. package/build/src/runtime/store/HistorySdk.js +25 -70
  30. package/build/src/runtime/store/HistorySdk.js.map +1 -1
  31. package/build/src/runtime/store/OrganizationsSdk.d.ts.map +1 -1
  32. package/build/src/runtime/store/OrganizationsSdk.js +46 -50
  33. package/build/src/runtime/store/OrganizationsSdk.js.map +1 -1
  34. package/build/src/runtime/store/RevisionsSdk.d.ts.map +1 -1
  35. package/build/src/runtime/store/RevisionsSdk.js +5 -10
  36. package/build/src/runtime/store/RevisionsSdk.js.map +1 -1
  37. package/build/src/runtime/store/SdkBase.d.ts +7 -5
  38. package/build/src/runtime/store/SdkBase.d.ts.map +1 -1
  39. package/build/src/runtime/store/SdkBase.js +45 -63
  40. package/build/src/runtime/store/SdkBase.js.map +1 -1
  41. package/build/src/runtime/store/SharedSdk.d.ts.map +1 -1
  42. package/build/src/runtime/store/SharedSdk.js +5 -14
  43. package/build/src/runtime/store/SharedSdk.js.map +1 -1
  44. package/build/src/runtime/store/TrashSdk.d.ts.map +1 -1
  45. package/build/src/runtime/store/TrashSdk.js +8 -28
  46. package/build/src/runtime/store/TrashSdk.js.map +1 -1
  47. package/build/src/runtime/store/UsersSdk.d.ts.map +1 -1
  48. package/build/src/runtime/store/UsersSdk.js +12 -11
  49. package/build/src/runtime/store/UsersSdk.js.map +1 -1
  50. package/package.json +1 -1
  51. package/src/exceptions/exception.ts +51 -4
  52. package/src/models/store/Backend.ts +16 -2
  53. package/src/proxy/HttpProjectProxy.ts +39 -43
  54. package/src/proxy/RequestProxy.ts +11 -11
  55. package/src/runtime/store/DataCatalogSdk.ts +49 -109
  56. package/src/runtime/store/FilesSdk.ts +51 -115
  57. package/src/runtime/store/HistorySdk.ts +25 -70
  58. package/src/runtime/store/OrganizationsSdk.ts +46 -50
  59. package/src/runtime/store/RevisionsSdk.ts +5 -10
  60. package/src/runtime/store/SdkBase.ts +46 -65
  61. package/src/runtime/store/SharedSdk.ts +5 -14
  62. package/src/runtime/store/TrashSdk.ts +8 -28
  63. package/src/runtime/store/UsersSdk.ts +12 -11
  64. package/tests/unit/runtime/proxy/HttpProjectProxy.spec.ts +42 -40
  65. package/tests/unit/runtime/proxy/RequestProxy.spec.ts +11 -11
  66. package/build/src/runtime/store/Errors.d.ts +0 -51
  67. package/build/src/runtime/store/Errors.d.ts.map +0 -1
  68. package/build/src/runtime/store/Errors.js +0 -61
  69. package/build/src/runtime/store/Errors.js.map +0 -1
  70. package/src/runtime/store/Errors.ts +0 -98
@@ -10,7 +10,6 @@ import { RouteBuilder } from './RouteBuilder.js'
10
10
  import { IUser } from '../../models/store/User.js'
11
11
  import { FileBreadcrumb, IFile } from '../../models/store/File.js'
12
12
  import { FolderKind, CertificateFileKind, ProjectKind, DomainFileKind } from '../../models/kinds.js'
13
- import { SdkError } from './Errors.js'
14
13
  import {
15
14
  ContextListResult,
16
15
  ContextChangeRecord,
@@ -21,6 +20,7 @@ import { IAccessAddOperation, IAccessRemoveOperation, PermissionRole } from '../
21
20
  import { nanoid } from 'nanoid'
22
21
  import { Folder, type IFolder } from '../../models/Folder.js'
23
22
  import type { AccessPatchInfo, MediaPatchInfo, MediaPatchRevision, PatchInfo } from '../../patch/types.js'
23
+ import { Exception } from '../../exceptions/exception.js'
24
24
 
25
25
  export interface IMetaCreateOptions {
26
26
  /**
@@ -76,24 +76,19 @@ export class FilesSdk extends SdkBase {
76
76
  const E_PREFIX = 'Unable to list files. '
77
77
  if (result.status !== 200) {
78
78
  this.logInvalidResponse(result)
79
- let e = this.createGenericSdkError(result.body)
80
- if (!e) {
81
- e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)
82
- e.response = result.body
83
- }
84
- throw e
79
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
85
80
  }
86
81
  if (!result.body) {
87
- throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`)
82
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
88
83
  }
89
84
  let data: ContextListResult<IFile>
90
85
  try {
91
86
  data = JSON.parse(result.body)
92
87
  } catch {
93
- throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`)
88
+ throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
94
89
  }
95
90
  if (!Array.isArray(data.items)) {
96
- throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`)
91
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
97
92
  }
98
93
  return data
99
94
  }
@@ -150,25 +145,20 @@ export class FilesSdk extends SdkBase {
150
145
  const E_PREFIX = 'Unable to create a file. '
151
146
  if (result.status !== 201) {
152
147
  this.logInvalidResponse(result)
153
- let e = this.createGenericSdkError(result.body)
154
- if (!e) {
155
- e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)
156
- e.response = result.body
157
- }
158
- throw e
148
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
159
149
  }
160
150
 
161
151
  if (!result.body) {
162
- throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`)
152
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
163
153
  }
164
154
  let data: ContextChangeRecord<IFile>
165
155
  try {
166
156
  data = JSON.parse(result.body)
167
157
  } catch {
168
- throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`)
158
+ throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
169
159
  }
170
160
  if (!data.key) {
171
- throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`)
161
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
172
162
  }
173
163
  return data
174
164
  }
@@ -209,12 +199,7 @@ export class FilesSdk extends SdkBase {
209
199
  const E_PREFIX = 'Unable to create a file. '
210
200
  if (result.status !== 200) {
211
201
  this.logInvalidResponse(result)
212
- let e = this.createGenericSdkError(result.body)
213
- if (!e) {
214
- e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)
215
- e.response = result.body
216
- }
217
- throw e
202
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
218
203
  }
219
204
  }
220
205
 
@@ -242,25 +227,20 @@ export class FilesSdk extends SdkBase {
242
227
  const E_PREFIX = 'Unable to create a file. '
243
228
  if (result.status !== 201) {
244
229
  this.logInvalidResponse(result)
245
- let e = this.createGenericSdkError(result.body)
246
- if (!e) {
247
- e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)
248
- e.response = result.body
249
- }
250
- throw e
230
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
251
231
  }
252
232
 
253
233
  if (!result.body) {
254
- throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`)
234
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
255
235
  }
256
236
  let data: IFolder
257
237
  try {
258
238
  data = JSON.parse(result.body)
259
239
  } catch {
260
- throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`)
240
+ throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
261
241
  }
262
242
  if (!data.key) {
263
- throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`)
243
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
264
244
  }
265
245
  return data
266
246
  }
@@ -280,24 +260,19 @@ export class FilesSdk extends SdkBase {
280
260
  const E_PREFIX = 'Unable to read a file. '
281
261
  if (result.status !== 200) {
282
262
  this.logInvalidResponse(result)
283
- let e = this.createGenericSdkError(result.body)
284
- if (!e) {
285
- e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)
286
- e.response = result.body
287
- }
288
- throw e
263
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
289
264
  }
290
265
  if (!result.body) {
291
- throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`)
266
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
292
267
  }
293
268
  let data: IFile
294
269
  try {
295
270
  data = JSON.parse(result.body)
296
271
  } catch {
297
- throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`)
272
+ throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
298
273
  }
299
274
  if (!data.kind) {
300
- throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`)
275
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
301
276
  }
302
277
  return data
303
278
  }
@@ -310,29 +285,30 @@ export class FilesSdk extends SdkBase {
310
285
  const E_PREFIX = 'Unable to read a file media. '
311
286
  if (result.status !== 200) {
312
287
  this.logInvalidResponse(result)
313
- let e = this.createGenericSdkError(result.body)
314
- if (!e) {
315
- e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)
316
- e.response = result.body
317
- }
318
- throw e
288
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
319
289
  }
320
290
  if (!result.body) {
321
- throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`)
291
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
322
292
  }
323
293
  let data: unknown
324
294
  try {
325
295
  data = JSON.parse(result.body)
326
296
  } catch {
327
- throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`)
297
+ throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
328
298
  }
329
299
  const versionStr = result.headers.get('x-version')
330
300
  if (!versionStr) {
331
- throw new Error(`${E_PREFIX}The file media version was not sent by the server.`)
301
+ throw new Exception(`${E_PREFIX}The file media version was not sent by the server.`, {
302
+ status: result.status,
303
+ code: 'E_RESPONSE_NO_VERSION',
304
+ })
332
305
  }
333
306
  const version = Number(versionStr)
334
307
  if (isNaN(version)) {
335
- throw new Error(`${E_PREFIX}The file media version is not a number.`)
308
+ throw new Exception(`${E_PREFIX}The file media version is not a number.`, {
309
+ status: result.status,
310
+ code: 'E_RESPONSE_INVALID_VERSION',
311
+ })
336
312
  }
337
313
  return {
338
314
  media: data,
@@ -356,24 +332,19 @@ export class FilesSdk extends SdkBase {
356
332
  const E_PREFIX = 'Unable to read files in bulk. '
357
333
  if (result.status !== 200) {
358
334
  this.logInvalidResponse(result)
359
- let e = this.createGenericSdkError(result.body)
360
- if (!e) {
361
- e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)
362
- e.response = result.body
363
- }
364
- throw e
335
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
365
336
  }
366
337
  if (!result.body) {
367
- throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`)
338
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
368
339
  }
369
340
  let data: IBulkOperationResult<IFile>
370
341
  try {
371
342
  data = JSON.parse(result.body)
372
343
  } catch {
373
- throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`)
344
+ throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
374
345
  }
375
346
  if (!Array.isArray(data.items)) {
376
- throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`)
347
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
377
348
  }
378
349
  return data
379
350
  }
@@ -395,24 +366,19 @@ export class FilesSdk extends SdkBase {
395
366
  const E_PREFIX = 'Unable to patch a file. '
396
367
  if (result.status !== 200) {
397
368
  this.logInvalidResponse(result)
398
- let e = this.createGenericSdkError(result.body)
399
- if (!e) {
400
- e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)
401
- e.response = result.body
402
- }
403
- throw e
369
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
404
370
  }
405
371
  if (!result.body) {
406
- throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`)
372
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
407
373
  }
408
374
  let data: IFile
409
375
  try {
410
376
  data = JSON.parse(result.body)
411
377
  } catch {
412
- throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`)
378
+ throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
413
379
  }
414
380
  if (!data.kind) {
415
- throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`)
381
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
416
382
  }
417
383
  return data
418
384
  }
@@ -435,21 +401,16 @@ export class FilesSdk extends SdkBase {
435
401
  const E_PREFIX = 'Unable to patch a file contents. '
436
402
  if (result.status !== 200) {
437
403
  this.logInvalidResponse(result)
438
- let e = this.createGenericSdkError(result.body)
439
- if (!e) {
440
- e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)
441
- e.response = result.body
442
- }
443
- throw e
404
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
444
405
  }
445
406
  if (!result.body) {
446
- throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`)
407
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
447
408
  }
448
409
  let data: MediaPatchRevision
449
410
  try {
450
411
  data = JSON.parse(result.body)
451
412
  } catch {
452
- throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`)
413
+ throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
453
414
  }
454
415
  return data
455
416
  }
@@ -469,12 +430,7 @@ export class FilesSdk extends SdkBase {
469
430
  const E_PREFIX = 'Unable to trash a file. '
470
431
  if (result.status !== 204) {
471
432
  this.logInvalidResponse(result)
472
- let e = this.createGenericSdkError(result.body)
473
- if (!e) {
474
- e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)
475
- e.response = result.body
476
- }
477
- throw e
433
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
478
434
  }
479
435
  }
480
436
 
@@ -486,12 +442,7 @@ export class FilesSdk extends SdkBase {
486
442
  const E_PREFIX = 'Unable to trash files. '
487
443
  if (result.status !== 204) {
488
444
  this.logInvalidResponse(result)
489
- let e = this.createGenericSdkError(result.body)
490
- if (!e) {
491
- e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)
492
- e.response = result.body
493
- }
494
- throw e
445
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
495
446
  }
496
447
  }
497
448
 
@@ -512,12 +463,7 @@ export class FilesSdk extends SdkBase {
512
463
  const E_PREFIX = 'Unable to patch the file. '
513
464
  if (result.status !== 204) {
514
465
  this.logInvalidResponse(result)
515
- let e = this.createGenericSdkError(result.body)
516
- if (!e) {
517
- e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)
518
- e.response = result.body
519
- }
520
- throw e
466
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
521
467
  }
522
468
  }
523
469
 
@@ -588,24 +534,19 @@ export class FilesSdk extends SdkBase {
588
534
  const E_PREFIX = 'Unable to list users in the file. '
589
535
  if (result.status !== 200) {
590
536
  this.logInvalidResponse(result)
591
- let e = this.createGenericSdkError(result.body)
592
- if (!e) {
593
- e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)
594
- e.response = result.body
595
- }
596
- throw e
537
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
597
538
  }
598
539
  if (!result.body) {
599
- throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`)
540
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
600
541
  }
601
542
  let data: ContextListResult<IUser>
602
543
  try {
603
544
  data = JSON.parse(result.body)
604
545
  } catch {
605
- throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`)
546
+ throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
606
547
  }
607
548
  if (!Array.isArray(data.items)) {
608
- throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`)
549
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
609
550
  }
610
551
  return data
611
552
  }
@@ -626,24 +567,19 @@ export class FilesSdk extends SdkBase {
626
567
  const E_PREFIX = 'Unable to read a file. '
627
568
  if (result.status !== 200) {
628
569
  this.logInvalidResponse(result)
629
- let e = this.createGenericSdkError(result.body)
630
- if (!e) {
631
- e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)
632
- e.response = result.body
633
- }
634
- throw e
570
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
635
571
  }
636
572
  if (!result.body) {
637
- throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`)
573
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
638
574
  }
639
575
  let data: ContextListResult<FileBreadcrumb>
640
576
  try {
641
577
  data = JSON.parse(result.body)
642
578
  } catch {
643
- throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`)
579
+ throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
644
580
  }
645
581
  if (!Array.isArray(data.items)) {
646
- throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`)
582
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
647
583
  }
648
584
  return data
649
585
  }
@@ -16,7 +16,7 @@ import {
16
16
  IBulkOperationResult,
17
17
  IHistoryRequestListOptions,
18
18
  } from '../../events/BaseEvents.js'
19
- import { SdkError } from './Errors.js'
19
+ import { Exception } from '../../exceptions/exception.js'
20
20
 
21
21
  export class HistorySdk extends SdkBase {
22
22
  /**
@@ -41,24 +41,19 @@ export class HistorySdk extends SdkBase {
41
41
  const E_PREFIX = 'Unable to create a history. '
42
42
  if (result.status !== 200) {
43
43
  this.logInvalidResponse(result)
44
- let e = this.createGenericSdkError(result.body)
45
- if (!e) {
46
- e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)
47
- e.response = result.body
48
- }
49
- throw e
44
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
50
45
  }
51
46
  if (!result.body) {
52
- throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`)
47
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
53
48
  }
54
49
  let data: ContextChangeRecord<IHttpHistory>
55
50
  try {
56
51
  data = JSON.parse(result.body)
57
52
  } catch {
58
- throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`)
53
+ throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
59
54
  }
60
55
  if (!data.key) {
61
- throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`)
56
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
62
57
  }
63
58
  return data
64
59
  }
@@ -81,24 +76,19 @@ export class HistorySdk extends SdkBase {
81
76
  const E_PREFIX = 'Unable to create a bulk history. '
82
77
  if (result.status !== 200) {
83
78
  this.logInvalidResponse(result)
84
- let e = this.createGenericSdkError(result.body)
85
- if (!e) {
86
- e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)
87
- e.response = result.body
88
- }
89
- throw e
79
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
90
80
  }
91
81
  if (!result.body) {
92
- throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`)
82
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
93
83
  }
94
84
  let data: IBulkOperationResult<ContextChangeRecord<IHttpHistory>>
95
85
  try {
96
86
  data = JSON.parse(result.body)
97
87
  } catch {
98
- throw new Error(`${E_PREFIX}${E_INVALID_JSON}`)
88
+ throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
99
89
  }
100
90
  if (!data.items) {
101
- throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`)
91
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
102
92
  }
103
93
  return data
104
94
  }
@@ -118,24 +108,19 @@ export class HistorySdk extends SdkBase {
118
108
  const E_PREFIX = 'Unable to list history. '
119
109
  if (result.status !== 200) {
120
110
  this.logInvalidResponse(result)
121
- let e = this.createGenericSdkError(result.body)
122
- if (!e) {
123
- e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)
124
- e.response = result.body
125
- }
126
- throw e
111
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
127
112
  }
128
113
  if (!result.body) {
129
- throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`)
114
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
130
115
  }
131
116
  let data: ContextListResult<IHttpHistory>
132
117
  try {
133
118
  data = JSON.parse(result.body)
134
119
  } catch {
135
- throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`)
120
+ throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
136
121
  }
137
122
  if (!Array.isArray(data.items)) {
138
- throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`)
123
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
139
124
  }
140
125
  return data
141
126
  }
@@ -176,12 +161,7 @@ export class HistorySdk extends SdkBase {
176
161
  const E_PREFIX = 'Unable to delete history. '
177
162
  if (result.status !== 204) {
178
163
  this.logInvalidResponse(result)
179
- let e = this.createGenericSdkError(result.body)
180
- if (!e) {
181
- e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)
182
- e.response = result.body
183
- }
184
- throw e
164
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
185
165
  }
186
166
  }
187
167
 
@@ -200,25 +180,20 @@ export class HistorySdk extends SdkBase {
200
180
  const E_PREFIX = 'Unable to delete history. '
201
181
  if (result.status !== 200) {
202
182
  this.logInvalidResponse(result)
203
- let e = this.createGenericSdkError(result.body)
204
- if (!e) {
205
- e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)
206
- e.response = result.body
207
- }
208
- throw e
183
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
209
184
  }
210
185
  if (!result.body) {
211
- throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`)
186
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
212
187
  }
213
188
 
214
189
  let data: IBulkOperationResult<ContextDeleteRecord>
215
190
  try {
216
191
  data = JSON.parse(result.body)
217
192
  } catch {
218
- throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`)
193
+ throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
219
194
  }
220
195
  if (!Array.isArray(data.items)) {
221
- throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`)
196
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
222
197
  }
223
198
  return data
224
199
  }
@@ -237,24 +212,19 @@ export class HistorySdk extends SdkBase {
237
212
  const E_PREFIX = 'Unable to read a history. '
238
213
  if (result.status !== 200) {
239
214
  this.logInvalidResponse(result)
240
- let e = this.createGenericSdkError(result.body)
241
- if (!e) {
242
- e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)
243
- e.response = result.body
244
- }
245
- throw e
215
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
246
216
  }
247
217
  if (!result.body) {
248
- throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`)
218
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
249
219
  }
250
220
  let data: IHttpHistory
251
221
  try {
252
222
  data = JSON.parse(result.body)
253
223
  } catch {
254
- throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`)
224
+ throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
255
225
  }
256
226
  if (data.kind !== HttpHistoryKind) {
257
- throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`)
227
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
258
228
  }
259
229
  return data
260
230
  }
@@ -267,12 +237,7 @@ export class HistorySdk extends SdkBase {
267
237
  const E_PREFIX = 'Unable to clear history for the organization. '
268
238
  if (result.status !== 204) {
269
239
  this.logInvalidResponse(result)
270
- let e = this.createGenericSdkError(result.body)
271
- if (!e) {
272
- e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)
273
- e.response = result.body
274
- }
275
- throw e
240
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
276
241
  }
277
242
  }
278
243
 
@@ -284,12 +249,7 @@ export class HistorySdk extends SdkBase {
284
249
  const E_PREFIX = 'Unable to clear history for the project. '
285
250
  if (result.status !== 204) {
286
251
  this.logInvalidResponse(result)
287
- let e = this.createGenericSdkError(result.body)
288
- if (!e) {
289
- e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)
290
- e.response = result.body
291
- }
292
- throw e
252
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
293
253
  }
294
254
  }
295
255
 
@@ -306,12 +266,7 @@ export class HistorySdk extends SdkBase {
306
266
  const E_PREFIX = 'Unable to clear history for the request. '
307
267
  if (result.status !== 204) {
308
268
  this.logInvalidResponse(result)
309
- let e = this.createGenericSdkError(result.body)
310
- if (!e) {
311
- e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)
312
- e.response = result.body
313
- }
314
- throw e
269
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
315
270
  }
316
271
  }
317
272
  }