wapi-client 0.9.4 → 0.9.6

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.
@@ -16,6 +16,7 @@ var __spreadValues = (a, b) => {
16
16
  };
17
17
 
18
18
  // src/lib/errors.ts
19
+ import { debugLog } from "./debug";
19
20
  var ERROR_GROUPS = {
20
21
  JSONRPC: {
21
22
  min: -32700,
@@ -382,6 +383,11 @@ var ERROR_GROUPS = {
382
383
  message: "TR_WITHDRAWAL_CANT_RV_WITHOUT_FLAG",
383
384
  description: `Withdrawals are expected connection points with outside systems, thus extra validation is required. Reversing a Transfer.type = 'withdrawal' requires reverse_withdrawal option to be true.`
384
385
  },
386
+ TR_UNIQUE_IDENTIFIER: {
387
+ code: -19115,
388
+ message: "TR_UNIQUE_IDENTIFIER",
389
+ description: `The identifier for Transfer object must be unique`
390
+ },
385
391
  TRG_SINGLE_PENDING_TR_CANT_RV: {
386
392
  code: -19200,
387
393
  message: "TRG_SINGLE_PENDING_TR_CANT_RV",
@@ -401,6 +407,26 @@ var ERROR_GROUPS = {
401
407
  code: -19203,
402
408
  message: "TRG_WITHDRAWAL_CANT_RV_WITHOUT_FLAG",
403
409
  description: `TransferGroup includes Transfer.type = 'withdrawal', thus for extra validation the reverse_withdrawal option must be set true`
410
+ },
411
+ TRG_UNIQUE_IDENTIFIER: {
412
+ code: -19204,
413
+ message: "TRG_UNIQUE_IDENTIFIER",
414
+ description: `The identifier for TransferGroup object must be unique`
415
+ },
416
+ TOKEN_UNIQUE_FOREIGN: {
417
+ code: -19300,
418
+ message: "TOKEN_UNIQUE_FOREIGN",
419
+ description: `The foreign for Token object must be unique`
420
+ },
421
+ WALLET_UNIQUE_FOREIGN: {
422
+ code: -19400,
423
+ message: "WALLET_UNIQUE_FOREIGN",
424
+ description: `The foreign for Wallet object must be unique`
425
+ },
426
+ UNIQUE_CONSTRAINT: {
427
+ code: -19500,
428
+ message: "UNIQUE_CONSTRAINT",
429
+ description: `Insert violates unique constraint`
404
430
  }
405
431
  }
406
432
  },
@@ -441,9 +467,9 @@ var WAPIError = class extends Error {
441
467
  var _a;
442
468
  super(message);
443
469
  const errorType = (_a = ERRORS[type]) != null ? _a : ERRORS.INTERNAL_SERVER_ERROR;
444
- this.type = ERRORS[type] ? type : ERROR_TYPES.INTERNAL_SERVER_ERROR;
445
- this.code = code || errorType.code;
446
- this.message = message || errorType.message;
470
+ this.type = type != null ? type : ERROR_TYPES.INTERNAL_SERVER_ERROR;
471
+ this.code = code != null ? code : errorType.code;
472
+ this.message = message != null ? message : errorType.message;
447
473
  this.data = __spreadValues({
448
474
  description: errorType.description
449
475
  }, data && typeof data === "object" ? data : { error: data });
@@ -457,11 +483,12 @@ var WAPIError = class extends Error {
457
483
  }
458
484
  };
459
485
  var JSONRPCError = class extends WAPIError {
460
- constructor(type, data, message) {
486
+ constructor(type, data, message, code) {
461
487
  super({
462
488
  type,
463
489
  message,
464
- data
490
+ data,
491
+ code
465
492
  });
466
493
  }
467
494
  static get group() {
@@ -472,11 +499,12 @@ var JSONRPCError = class extends WAPIError {
472
499
  }
473
500
  };
474
501
  var StreamError = class extends WAPIError {
475
- constructor(type, data, message) {
502
+ constructor(type, data, message, code) {
476
503
  super({
477
504
  type,
478
505
  message,
479
- data
506
+ data,
507
+ code
480
508
  });
481
509
  }
482
510
  static get group() {
@@ -487,11 +515,12 @@ var StreamError = class extends WAPIError {
487
515
  }
488
516
  };
489
517
  var InputError = class extends WAPIError {
490
- constructor(type, data, message) {
518
+ constructor(type, data, message, code) {
491
519
  super({
492
520
  type,
493
521
  message,
494
- data
522
+ data,
523
+ code
495
524
  });
496
525
  }
497
526
  static get group() {
@@ -502,11 +531,12 @@ var InputError = class extends WAPIError {
502
531
  }
503
532
  };
504
533
  var ConfigError = class extends WAPIError {
505
- constructor(type, data, message) {
534
+ constructor(type, data, message, code) {
506
535
  super({
507
536
  type,
508
537
  message,
509
- data
538
+ data,
539
+ code
510
540
  });
511
541
  }
512
542
  static get group() {
@@ -517,11 +547,12 @@ var ConfigError = class extends WAPIError {
517
547
  }
518
548
  };
519
549
  var AuthError = class extends WAPIError {
520
- constructor(type, data, message) {
550
+ constructor(type, data, message, code) {
521
551
  super({
522
552
  type,
523
553
  message,
524
- data
554
+ data,
555
+ code
525
556
  });
526
557
  }
527
558
  static get group() {
@@ -532,11 +563,12 @@ var AuthError = class extends WAPIError {
532
563
  }
533
564
  };
534
565
  var ConstraintError = class extends WAPIError {
535
- constructor(type, data, message) {
566
+ constructor(type, data, message, code) {
536
567
  super({
537
568
  type,
538
569
  message,
539
- data
570
+ data,
571
+ code
540
572
  });
541
573
  }
542
574
  static get group() {
@@ -608,8 +640,11 @@ var ERROR_CODE_TO_TYPE = Object.fromEntries(
608
640
  function categorizeErrorCode(code) {
609
641
  const type = ERROR_CODE_TO_TYPE[code];
610
642
  if (!type) {
643
+ const group2 = Object.entries(ERROR_GROUPS).find(
644
+ ([key, group3]) => code >= group3.min && code <= group3.max
645
+ );
611
646
  return {
612
- group: void 0,
647
+ group: group2 == null ? void 0 : group2[0],
613
648
  type: void 0
614
649
  };
615
650
  }
@@ -629,8 +664,15 @@ function categorizeErrorCode(code) {
629
664
  };
630
665
  }
631
666
  function getError({ code, message, data }) {
632
- const { group, type } = categorizeErrorCode(code);
667
+ let { group, type } = categorizeErrorCode(code);
633
668
  message = message && message !== type ? message : ERRORS[type].description;
669
+ let novelCode = void 0;
670
+ if (group && group !== "JSONRPC" && type === void 0) {
671
+ debugLog("Novel error from server", code, message, data);
672
+ type = message;
673
+ novelCode = code;
674
+ message = typeof data === "object" && "description" in data && typeof data.description === "string" ? data.description : message;
675
+ }
634
676
  switch (group) {
635
677
  case "JSONRPC":
636
678
  return new JSONRPCError(
@@ -642,31 +684,36 @@ function getError({ code, message, data }) {
642
684
  return new AuthError(
643
685
  type,
644
686
  data,
645
- message
687
+ message,
688
+ novelCode
646
689
  );
647
690
  case "CONFIG":
648
691
  return new ConfigError(
649
692
  type,
650
693
  data,
651
- message
694
+ message,
695
+ novelCode
652
696
  );
653
697
  case "CONSTRAINT":
654
698
  return new ConstraintError(
655
699
  type,
656
700
  data,
657
- message
701
+ message,
702
+ novelCode
658
703
  );
659
704
  case "INPUT":
660
705
  return new InputError(
661
706
  type,
662
707
  data,
663
- message
708
+ message,
709
+ novelCode
664
710
  );
665
711
  case "STREAM":
666
712
  return new StreamError(
667
713
  type,
668
714
  data,
669
- message
715
+ message,
716
+ novelCode
670
717
  );
671
718
  default:
672
719
  return new WAPIError({