@bombillazo/error-x 0.4.4 → 0.4.5

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/dist/index.cjs CHANGED
@@ -16,9 +16,7 @@ var ERROR_X_OPTION_FIELDS = [
16
16
  "uiMessage",
17
17
  "cause",
18
18
  "metadata",
19
- "httpStatus",
20
19
  "type",
21
- "sourceUrl",
22
20
  "docsUrl",
23
21
  "source"
24
22
  ];
@@ -36,12 +34,8 @@ var ErrorX = class _ErrorX extends Error {
36
34
  metadata;
37
35
  /** Unix epoch timestamp (milliseconds) when the error was created */
38
36
  timestamp;
39
- /** HTTP status code (100-599) for HTTP-related errors */
40
- httpStatus;
41
37
  /** Error type for categorization */
42
38
  type;
43
- /** Source URL related to the error (API endpoint, page URL, resource URL) */
44
- sourceUrl;
45
39
  /** Documentation URL for this specific error */
46
40
  docsUrl;
47
41
  /** Where the error originated (service name, module, component) */
@@ -98,10 +92,8 @@ var ErrorX = class _ErrorX extends Error {
98
92
  this.code = options.code != null ? String(options.code) : _ErrorX.generateDefaultCode(options.name);
99
93
  this.uiMessage = options.uiMessage;
100
94
  this.metadata = options.metadata;
101
- this.httpStatus = _ErrorX.validateHttpStatus(options.httpStatus);
102
95
  this.type = _ErrorX.validateType(options.type);
103
96
  this.timestamp = Date.now();
104
- this.sourceUrl = options.sourceUrl;
105
97
  this.source = options.source ?? envConfig?.source;
106
98
  let generatedDocsUrl;
107
99
  if (envConfig?.docsBaseURL && envConfig?.docsMap && this.code) {
@@ -209,22 +201,6 @@ var ErrorX = class _ErrorX extends Error {
209
201
  static resetConfig() {
210
202
  _ErrorX._config = null;
211
203
  }
212
- /**
213
- * Validates HTTP status code to ensure it's within valid range (100-599)
214
- *
215
- * @param status - Status code to validate
216
- * @returns Valid status code or undefined if invalid/not provided
217
- */
218
- static validateHttpStatus(status) {
219
- if (status === void 0 || status === null) {
220
- return void 0;
221
- }
222
- const statusNum = Number(status);
223
- if (Number.isNaN(statusNum) || statusNum < 100 || statusNum > 599) {
224
- return void 0;
225
- }
226
- return Math.floor(statusNum);
227
- }
228
204
  /**
229
205
  * Validates and normalizes the type field
230
206
  *
@@ -376,9 +352,7 @@ var ErrorX = class _ErrorX extends Error {
376
352
  uiMessage: this.uiMessage,
377
353
  cause: this.cause,
378
354
  metadata: { ...this.metadata ?? {}, ...additionalMetadata },
379
- httpStatus: this.httpStatus,
380
355
  type: this.type,
381
- sourceUrl: this.sourceUrl,
382
356
  docsUrl: this.docsUrl,
383
357
  source: this.source
384
358
  };
@@ -426,9 +400,7 @@ var ErrorX = class _ErrorX extends Error {
426
400
  let uiMessage = "";
427
401
  let cause;
428
402
  let metadata = {};
429
- let httpStatus;
430
403
  let type;
431
- let url;
432
404
  let href;
433
405
  let source;
434
406
  if (error) {
@@ -453,26 +425,9 @@ var ErrorX = class _ErrorX extends Error {
453
425
  if ("code" in error && error.code) code = String(error.code);
454
426
  if ("uiMessage" in error && error.uiMessage) uiMessage = String(error.uiMessage);
455
427
  else if ("userMessage" in error && error.userMessage) uiMessage = String(error.userMessage);
456
- let _httpStatus;
457
- if ("httpStatus" in error) {
458
- _httpStatus = error.httpStatus;
459
- } else if ("status" in error) {
460
- _httpStatus = error.status;
461
- } else if ("statusCode" in error) {
462
- _httpStatus = error.statusCode;
463
- }
464
- if (_httpStatus !== void 0 && _httpStatus !== null) {
465
- const num = typeof _httpStatus === "number" ? _httpStatus : Number(_httpStatus);
466
- httpStatus = _ErrorX.validateHttpStatus(num);
467
- }
468
428
  if ("type" in error && error.type) {
469
429
  type = _ErrorX.validateType(String(error.type));
470
430
  }
471
- if ("sourceUrl" in error && error.sourceUrl) {
472
- url = String(error.sourceUrl);
473
- } else if ("url" in error && error.url) {
474
- url = String(error.url);
475
- }
476
431
  if ("docsUrl" in error && error.docsUrl) {
477
432
  href = String(error.docsUrl);
478
433
  } else if ("href" in error && error.href) {
@@ -498,9 +453,7 @@ var ErrorX = class _ErrorX extends Error {
498
453
  if (uiMessage) options.uiMessage = uiMessage;
499
454
  if (cause) options.cause = cause;
500
455
  if (Object.keys(metadata).length > 0) options.metadata = metadata;
501
- if (httpStatus) options.httpStatus = httpStatus;
502
456
  if (type) options.type = type;
503
- if (url) options.sourceUrl = url;
504
457
  if (href) options.docsUrl = href;
505
458
  if (source) options.source = source;
506
459
  return options;
@@ -578,15 +531,9 @@ ${this.stack}`;
578
531
  metadata: safeMetadata,
579
532
  timestamp: this.timestamp
580
533
  };
581
- if (this.httpStatus !== void 0) {
582
- serialized.httpStatus = this.httpStatus;
583
- }
584
534
  if (this.type !== void 0) {
585
535
  serialized.type = this.type;
586
536
  }
587
- if (this.sourceUrl !== void 0) {
588
- serialized.sourceUrl = this.sourceUrl;
589
- }
590
537
  if (this.docsUrl !== void 0) {
591
538
  serialized.docsUrl = this.docsUrl;
592
539
  }
@@ -629,9 +576,7 @@ ${this.stack}`;
629
576
  name: serialized.name,
630
577
  code: serialized.code,
631
578
  uiMessage: serialized.uiMessage,
632
- httpStatus: serialized.httpStatus,
633
579
  type: serialized.type,
634
- sourceUrl: serialized.sourceUrl,
635
580
  docsUrl: serialized.docsUrl,
636
581
  source: serialized.source,
637
582
  cause: serialized.cause
@@ -652,317 +597,278 @@ ${this.stack}`;
652
597
  var http = {
653
598
  // 4xx Client Errors
654
599
  400: {
655
- httpStatus: 400,
656
600
  code: "BAD_REQUEST",
657
601
  name: "Bad Request Error",
658
602
  message: "Bad request.",
659
603
  uiMessage: "The request could not be processed. Please check your input and try again.",
660
- type: "http"
604
+ metadata: { status: 400 }
661
605
  },
662
606
  401: {
663
- httpStatus: 401,
664
607
  code: "UNAUTHORIZED",
665
608
  name: "Unauthorized Error",
666
609
  message: "Unauthorized.",
667
610
  uiMessage: "Authentication required. Please log in to continue.",
668
- type: "http"
611
+ metadata: { status: 401 }
669
612
  },
670
613
  402: {
671
- httpStatus: 402,
672
614
  code: "PAYMENT_REQUIRED",
673
615
  name: "Payment Required Error",
674
616
  message: "Payment required.",
675
617
  uiMessage: "Payment is required to access this resource.",
676
- type: "http"
618
+ metadata: { status: 402 }
677
619
  },
678
620
  403: {
679
- httpStatus: 403,
680
621
  code: "FORBIDDEN",
681
622
  name: "Forbidden Error",
682
623
  message: "Forbidden.",
683
624
  uiMessage: "You do not have permission to access this resource.",
684
- type: "http"
625
+ metadata: { status: 403 }
685
626
  },
686
627
  404: {
687
- httpStatus: 404,
688
628
  code: "NOT_FOUND",
689
629
  name: "Not Found Error",
690
630
  message: "Not found.",
691
631
  uiMessage: "The requested resource could not be found.",
692
- type: "http"
632
+ metadata: { status: 404 }
693
633
  },
694
634
  405: {
695
- httpStatus: 405,
696
635
  code: "METHOD_NOT_ALLOWED",
697
636
  name: "Method Not Allowed Error",
698
637
  message: "Method not allowed.",
699
638
  uiMessage: "This action is not allowed for the requested resource.",
700
- type: "http"
639
+ metadata: { status: 405 }
701
640
  },
702
641
  406: {
703
- httpStatus: 406,
704
642
  code: "NOT_ACCEPTABLE",
705
643
  name: "Not Acceptable Error",
706
644
  message: "Not acceptable.",
707
645
  uiMessage: "The requested format is not supported.",
708
- type: "http"
646
+ metadata: { status: 406 }
709
647
  },
710
648
  407: {
711
- httpStatus: 407,
712
649
  code: "PROXY_AUTHENTICATION_REQUIRED",
713
650
  name: "Proxy Authentication Required Error",
714
651
  message: "Proxy authentication required.",
715
652
  uiMessage: "Proxy authentication is required to access this resource.",
716
- type: "http"
653
+ metadata: { status: 407 }
717
654
  },
718
655
  408: {
719
- httpStatus: 408,
720
656
  code: "REQUEST_TIMEOUT",
721
657
  name: "Request Timeout Error",
722
658
  message: "Request timeout.",
723
659
  uiMessage: "The request took too long to complete. Please try again.",
724
- type: "http"
660
+ metadata: { status: 408 }
725
661
  },
726
662
  409: {
727
- httpStatus: 409,
728
663
  code: "CONFLICT",
729
664
  name: "Conflict Error",
730
665
  message: "Conflict.",
731
666
  uiMessage: "The request conflicts with the current state. Please refresh and try again.",
732
- type: "http"
667
+ metadata: { status: 409 }
733
668
  },
734
669
  410: {
735
- httpStatus: 410,
736
670
  code: "GONE",
737
671
  name: "Gone Error",
738
672
  message: "Gone.",
739
673
  uiMessage: "This resource is no longer available.",
740
- type: "http"
674
+ metadata: { status: 410 }
741
675
  },
742
676
  411: {
743
- httpStatus: 411,
744
677
  code: "LENGTH_REQUIRED",
745
678
  name: "Length Required Error",
746
679
  message: "Length required.",
747
680
  uiMessage: "The request is missing required length information.",
748
- type: "http"
681
+ metadata: { status: 411 }
749
682
  },
750
683
  412: {
751
- httpStatus: 412,
752
684
  code: "PRECONDITION_FAILED",
753
685
  name: "Precondition Failed Error",
754
686
  message: "Precondition failed.",
755
687
  uiMessage: "A required condition was not met. Please try again.",
756
- type: "http"
688
+ metadata: { status: 412 }
757
689
  },
758
690
  413: {
759
- httpStatus: 413,
760
691
  code: "PAYLOAD_TOO_LARGE",
761
692
  name: "Payload Too Large Error",
762
693
  message: "Payload too large.",
763
694
  uiMessage: "The request is too large. Please reduce the size and try again.",
764
- type: "http"
695
+ metadata: { status: 413 }
765
696
  },
766
697
  414: {
767
- httpStatus: 414,
768
698
  code: "URI_TOO_LONG",
769
699
  name: "URI Too Long Error",
770
700
  message: "URI too long.",
771
701
  uiMessage: "The request URL is too long.",
772
- type: "http"
702
+ metadata: { status: 414 }
773
703
  },
774
704
  415: {
775
- httpStatus: 415,
776
705
  code: "UNSUPPORTED_MEDIA_TYPE",
777
706
  name: "Unsupported Media Type Error",
778
707
  message: "Unsupported media type.",
779
708
  uiMessage: "The file type is not supported.",
780
- type: "http"
709
+ metadata: { status: 415 }
781
710
  },
782
711
  416: {
783
- httpStatus: 416,
784
712
  code: "RANGE_NOT_SATISFIABLE",
785
713
  name: "Range Not Satisfiable Error",
786
714
  message: "Range not satisfiable.",
787
715
  uiMessage: "The requested range cannot be satisfied.",
788
- type: "http"
716
+ metadata: { status: 416 }
789
717
  },
790
718
  417: {
791
- httpStatus: 417,
792
719
  code: "EXPECTATION_FAILED",
793
720
  name: "Expectation Failed Error",
794
721
  message: "Expectation failed.",
795
722
  uiMessage: "The server cannot meet the requirements of the request.",
796
- type: "http"
723
+ metadata: { status: 417 }
797
724
  },
798
725
  418: {
799
- httpStatus: 418,
800
726
  code: "IM_A_TEAPOT",
801
727
  name: "Im A Teapot Error",
802
728
  message: "I'm a teapot.",
803
729
  uiMessage: "I'm a teapot and cannot brew coffee.",
804
- type: "http"
730
+ metadata: { status: 418 }
805
731
  },
806
732
  422: {
807
- httpStatus: 422,
808
733
  code: "UNPROCESSABLE_ENTITY",
809
734
  name: "Unprocessable Entity Error",
810
735
  message: "Unprocessable entity.",
811
736
  uiMessage: "The request contains invalid data. Please check your input.",
812
- type: "http"
737
+ metadata: { status: 422 }
813
738
  },
814
739
  423: {
815
- httpStatus: 423,
816
740
  code: "LOCKED",
817
741
  name: "Locked Error",
818
742
  message: "Locked.",
819
743
  uiMessage: "This resource is locked and cannot be modified.",
820
- type: "http"
744
+ metadata: { status: 423 }
821
745
  },
822
746
  424: {
823
- httpStatus: 424,
824
747
  code: "FAILED_DEPENDENCY",
825
748
  name: "Failed Dependency Error",
826
749
  message: "Failed dependency.",
827
750
  uiMessage: "The request failed due to a dependency error.",
828
- type: "http"
751
+ metadata: { status: 424 }
829
752
  },
830
753
  425: {
831
- httpStatus: 425,
832
754
  code: "TOO_EARLY",
833
755
  name: "Too Early Error",
834
756
  message: "Too early.",
835
757
  uiMessage: "The request was sent too early. Please try again later.",
836
- type: "http"
758
+ metadata: { status: 425 }
837
759
  },
838
760
  426: {
839
- httpStatus: 426,
840
761
  code: "UPGRADE_REQUIRED",
841
762
  name: "Upgrade Required Error",
842
763
  message: "Upgrade required.",
843
764
  uiMessage: "Please upgrade to continue using this service.",
844
- type: "http"
765
+ metadata: { status: 426 }
845
766
  },
846
767
  428: {
847
- httpStatus: 428,
848
768
  code: "PRECONDITION_REQUIRED",
849
769
  name: "Precondition Required Error",
850
770
  message: "Precondition required.",
851
771
  uiMessage: "Required conditions are missing from the request.",
852
- type: "http"
772
+ metadata: { status: 428 }
853
773
  },
854
774
  429: {
855
- httpStatus: 429,
856
775
  code: "TOO_MANY_REQUESTS",
857
776
  name: "Too Many Requests Error",
858
777
  message: "Too many requests.",
859
778
  uiMessage: "You have made too many requests. Please wait and try again.",
860
- type: "http"
779
+ metadata: { status: 429 }
861
780
  },
862
781
  431: {
863
- httpStatus: 431,
864
782
  code: "REQUEST_HEADER_FIELDS_TOO_LARGE",
865
783
  name: "Request Header Fields Too Large Error",
866
784
  message: "Request header fields too large.",
867
785
  uiMessage: "The request headers are too large.",
868
- type: "http"
786
+ metadata: { status: 431 }
869
787
  },
870
788
  451: {
871
- httpStatus: 451,
872
789
  code: "UNAVAILABLE_FOR_LEGAL_REASONS",
873
790
  name: "Unavailable For Legal Reasons Error",
874
791
  message: "Unavailable for legal reasons.",
875
792
  uiMessage: "This content is unavailable for legal reasons.",
876
- type: "http"
793
+ metadata: { status: 451 }
877
794
  },
878
795
  // 5xx Server Errors
879
796
  500: {
880
- httpStatus: 500,
881
797
  code: "INTERNAL_SERVER_ERROR",
882
798
  name: "Internal Server Error",
883
799
  message: "Internal server error.",
884
800
  uiMessage: "An unexpected error occurred. Please try again later.",
885
- type: "http"
801
+ metadata: { status: 500 }
886
802
  },
887
803
  501: {
888
- httpStatus: 501,
889
804
  code: "NOT_IMPLEMENTED",
890
805
  name: "Not Implemented Error",
891
806
  message: "Not implemented.",
892
807
  uiMessage: "This feature is not yet available.",
893
- type: "http"
808
+ metadata: { status: 501 }
894
809
  },
895
810
  502: {
896
- httpStatus: 502,
897
811
  code: "BAD_GATEWAY",
898
812
  name: "Bad Gateway Error",
899
813
  message: "Bad gateway.",
900
814
  uiMessage: "Unable to connect to the server. Please try again later.",
901
- type: "http"
815
+ metadata: { status: 502 }
902
816
  },
903
817
  503: {
904
- httpStatus: 503,
905
818
  code: "SERVICE_UNAVAILABLE",
906
819
  name: "Service Unavailable Error",
907
820
  message: "Service unavailable.",
908
821
  uiMessage: "The service is temporarily unavailable. Please try again later.",
909
- type: "http"
822
+ metadata: { status: 503 }
910
823
  },
911
824
  504: {
912
- httpStatus: 504,
913
825
  code: "GATEWAY_TIMEOUT",
914
826
  name: "Gateway Timeout Error",
915
827
  message: "Gateway timeout.",
916
828
  uiMessage: "The server took too long to respond. Please try again.",
917
- type: "http"
829
+ metadata: { status: 504 }
918
830
  },
919
831
  505: {
920
- httpStatus: 505,
921
832
  code: "HTTP_VERSION_NOT_SUPPORTED",
922
833
  name: "HTTP Version Not Supported Error",
923
834
  message: "HTTP version not supported.",
924
835
  uiMessage: "Your browser version is not supported.",
925
- type: "http"
836
+ metadata: { status: 505 }
926
837
  },
927
838
  506: {
928
- httpStatus: 506,
929
839
  code: "VARIANT_ALSO_NEGOTIATES",
930
840
  name: "Variant Also Negotiates Error",
931
841
  message: "Variant also negotiates.",
932
842
  uiMessage: "The server has an internal configuration error.",
933
- type: "http"
843
+ metadata: { status: 506 }
934
844
  },
935
845
  507: {
936
- httpStatus: 507,
937
846
  code: "INSUFFICIENT_STORAGE",
938
847
  name: "Insufficient Storage Error",
939
848
  message: "Insufficient storage.",
940
849
  uiMessage: "The server has insufficient storage to complete the request.",
941
- type: "http"
850
+ metadata: { status: 507 }
942
851
  },
943
852
  508: {
944
- httpStatus: 508,
945
853
  code: "LOOP_DETECTED",
946
854
  name: "Loop Detected Error",
947
855
  message: "Loop detected.",
948
856
  uiMessage: "The server detected an infinite loop.",
949
- type: "http"
857
+ metadata: { status: 508 }
950
858
  },
951
859
  510: {
952
- httpStatus: 510,
953
860
  code: "NOT_EXTENDED",
954
861
  name: "Not Extended Error",
955
862
  message: "Not extended.",
956
863
  uiMessage: "Additional extensions are required.",
957
- type: "http"
864
+ metadata: { status: 510 }
958
865
  },
959
866
  511: {
960
- httpStatus: 511,
961
867
  code: "NETWORK_AUTHENTICATION_REQUIRED",
962
868
  name: "Network Authentication Required Error",
963
869
  message: "Network authentication required.",
964
870
  uiMessage: "Network authentication is required to access this resource.",
965
- type: "http"
871
+ metadata: { status: 511 }
966
872
  }
967
873
  };
968
874