@bombillazo/error-x 0.4.2 → 0.4.4
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/README.md +10 -10
- package/dist/index.cjs +47 -47
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +67 -67
- package/dist/index.d.ts +67 -67
- package/dist/index.js +47 -47
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -28,7 +28,7 @@ var ErrorX = class _ErrorX extends Error {
|
|
|
28
28
|
uiMessage;
|
|
29
29
|
/** Additional context and metadata associated with the error */
|
|
30
30
|
metadata;
|
|
31
|
-
/**
|
|
31
|
+
/** Unix epoch timestamp (milliseconds) when the error was created */
|
|
32
32
|
timestamp;
|
|
33
33
|
/** HTTP status code (100-599) for HTTP-related errors */
|
|
34
34
|
httpStatus;
|
|
@@ -94,7 +94,7 @@ var ErrorX = class _ErrorX extends Error {
|
|
|
94
94
|
this.metadata = options.metadata;
|
|
95
95
|
this.httpStatus = _ErrorX.validateHttpStatus(options.httpStatus);
|
|
96
96
|
this.type = _ErrorX.validateType(options.type);
|
|
97
|
-
this.timestamp =
|
|
97
|
+
this.timestamp = Date.now();
|
|
98
98
|
this.sourceUrl = options.sourceUrl;
|
|
99
99
|
this.source = options.source ?? envConfig?.source;
|
|
100
100
|
let generatedDocsUrl;
|
|
@@ -113,8 +113,8 @@ var ErrorX = class _ErrorX extends Error {
|
|
|
113
113
|
if (typeof Error.captureStackTrace === "function") {
|
|
114
114
|
Error.captureStackTrace(this, this.constructor);
|
|
115
115
|
}
|
|
116
|
-
this.stack = _ErrorX.cleanStack(this.stack);
|
|
117
116
|
}
|
|
117
|
+
this.stack = _ErrorX.cleanStack(this.stack);
|
|
118
118
|
}
|
|
119
119
|
/**
|
|
120
120
|
* Returns the default error name.
|
|
@@ -520,7 +520,7 @@ var ErrorX = class _ErrorX extends Error {
|
|
|
520
520
|
* })
|
|
521
521
|
*
|
|
522
522
|
* console.log(error.toString())
|
|
523
|
-
* // Output: "DatabaseError: Database connection failed. [DB_CONN_FAILED]
|
|
523
|
+
* // Output: "DatabaseError: Database connection failed. [DB_CONN_FAILED] 2025-01-15T10:30:45.123Z (1736937045123) metadata: {...}"
|
|
524
524
|
* ```
|
|
525
525
|
*/
|
|
526
526
|
toString() {
|
|
@@ -529,7 +529,7 @@ var ErrorX = class _ErrorX extends Error {
|
|
|
529
529
|
if (this.code && this.code !== "ERROR") {
|
|
530
530
|
parts.push(`[${this.code}]`);
|
|
531
531
|
}
|
|
532
|
-
parts.push(
|
|
532
|
+
parts.push(`${new Date(this.timestamp).toISOString()} (${this.timestamp})`);
|
|
533
533
|
if (this.metadata && Object.keys(this.metadata).length > 0) {
|
|
534
534
|
const metadataStr = safeStringify(this.metadata);
|
|
535
535
|
parts.push(`metadata: ${metadataStr}`);
|
|
@@ -570,7 +570,7 @@ ${this.stack}`;
|
|
|
570
570
|
code: this.code,
|
|
571
571
|
uiMessage: this.uiMessage,
|
|
572
572
|
metadata: safeMetadata,
|
|
573
|
-
timestamp: this.timestamp
|
|
573
|
+
timestamp: this.timestamp
|
|
574
574
|
};
|
|
575
575
|
if (this.httpStatus !== void 0) {
|
|
576
576
|
serialized.httpStatus = this.httpStatus;
|
|
@@ -610,7 +610,7 @@ ${this.stack}`;
|
|
|
610
610
|
* code: 'DB_CONN_FAILED',
|
|
611
611
|
* uiMessage: 'Database is temporarily unavailable',
|
|
612
612
|
* metadata: { host: 'localhost' },
|
|
613
|
-
* timestamp:
|
|
613
|
+
* timestamp: 1705315845123
|
|
614
614
|
* }
|
|
615
615
|
*
|
|
616
616
|
* const error = ErrorX.fromJSON(serializedError)
|
|
@@ -637,7 +637,7 @@ ${this.stack}`;
|
|
|
637
637
|
if (serialized.stack) {
|
|
638
638
|
error.stack = serialized.stack;
|
|
639
639
|
}
|
|
640
|
-
error.timestamp =
|
|
640
|
+
error.timestamp = serialized.timestamp;
|
|
641
641
|
return error;
|
|
642
642
|
}
|
|
643
643
|
};
|
|
@@ -645,7 +645,7 @@ ${this.stack}`;
|
|
|
645
645
|
// src/presets.ts
|
|
646
646
|
var http = {
|
|
647
647
|
// 4xx Client Errors
|
|
648
|
-
|
|
648
|
+
400: {
|
|
649
649
|
httpStatus: 400,
|
|
650
650
|
code: "BAD_REQUEST",
|
|
651
651
|
name: "Bad Request Error",
|
|
@@ -653,7 +653,7 @@ var http = {
|
|
|
653
653
|
uiMessage: "The request could not be processed. Please check your input and try again.",
|
|
654
654
|
type: "http"
|
|
655
655
|
},
|
|
656
|
-
|
|
656
|
+
401: {
|
|
657
657
|
httpStatus: 401,
|
|
658
658
|
code: "UNAUTHORIZED",
|
|
659
659
|
name: "Unauthorized Error",
|
|
@@ -661,7 +661,7 @@ var http = {
|
|
|
661
661
|
uiMessage: "Authentication required. Please log in to continue.",
|
|
662
662
|
type: "http"
|
|
663
663
|
},
|
|
664
|
-
|
|
664
|
+
402: {
|
|
665
665
|
httpStatus: 402,
|
|
666
666
|
code: "PAYMENT_REQUIRED",
|
|
667
667
|
name: "Payment Required Error",
|
|
@@ -669,7 +669,7 @@ var http = {
|
|
|
669
669
|
uiMessage: "Payment is required to access this resource.",
|
|
670
670
|
type: "http"
|
|
671
671
|
},
|
|
672
|
-
|
|
672
|
+
403: {
|
|
673
673
|
httpStatus: 403,
|
|
674
674
|
code: "FORBIDDEN",
|
|
675
675
|
name: "Forbidden Error",
|
|
@@ -677,7 +677,7 @@ var http = {
|
|
|
677
677
|
uiMessage: "You do not have permission to access this resource.",
|
|
678
678
|
type: "http"
|
|
679
679
|
},
|
|
680
|
-
|
|
680
|
+
404: {
|
|
681
681
|
httpStatus: 404,
|
|
682
682
|
code: "NOT_FOUND",
|
|
683
683
|
name: "Not Found Error",
|
|
@@ -685,7 +685,7 @@ var http = {
|
|
|
685
685
|
uiMessage: "The requested resource could not be found.",
|
|
686
686
|
type: "http"
|
|
687
687
|
},
|
|
688
|
-
|
|
688
|
+
405: {
|
|
689
689
|
httpStatus: 405,
|
|
690
690
|
code: "METHOD_NOT_ALLOWED",
|
|
691
691
|
name: "Method Not Allowed Error",
|
|
@@ -693,7 +693,7 @@ var http = {
|
|
|
693
693
|
uiMessage: "This action is not allowed for the requested resource.",
|
|
694
694
|
type: "http"
|
|
695
695
|
},
|
|
696
|
-
|
|
696
|
+
406: {
|
|
697
697
|
httpStatus: 406,
|
|
698
698
|
code: "NOT_ACCEPTABLE",
|
|
699
699
|
name: "Not Acceptable Error",
|
|
@@ -701,7 +701,7 @@ var http = {
|
|
|
701
701
|
uiMessage: "The requested format is not supported.",
|
|
702
702
|
type: "http"
|
|
703
703
|
},
|
|
704
|
-
|
|
704
|
+
407: {
|
|
705
705
|
httpStatus: 407,
|
|
706
706
|
code: "PROXY_AUTHENTICATION_REQUIRED",
|
|
707
707
|
name: "Proxy Authentication Required Error",
|
|
@@ -709,7 +709,7 @@ var http = {
|
|
|
709
709
|
uiMessage: "Proxy authentication is required to access this resource.",
|
|
710
710
|
type: "http"
|
|
711
711
|
},
|
|
712
|
-
|
|
712
|
+
408: {
|
|
713
713
|
httpStatus: 408,
|
|
714
714
|
code: "REQUEST_TIMEOUT",
|
|
715
715
|
name: "Request Timeout Error",
|
|
@@ -717,7 +717,7 @@ var http = {
|
|
|
717
717
|
uiMessage: "The request took too long to complete. Please try again.",
|
|
718
718
|
type: "http"
|
|
719
719
|
},
|
|
720
|
-
|
|
720
|
+
409: {
|
|
721
721
|
httpStatus: 409,
|
|
722
722
|
code: "CONFLICT",
|
|
723
723
|
name: "Conflict Error",
|
|
@@ -725,7 +725,7 @@ var http = {
|
|
|
725
725
|
uiMessage: "The request conflicts with the current state. Please refresh and try again.",
|
|
726
726
|
type: "http"
|
|
727
727
|
},
|
|
728
|
-
|
|
728
|
+
410: {
|
|
729
729
|
httpStatus: 410,
|
|
730
730
|
code: "GONE",
|
|
731
731
|
name: "Gone Error",
|
|
@@ -733,7 +733,7 @@ var http = {
|
|
|
733
733
|
uiMessage: "This resource is no longer available.",
|
|
734
734
|
type: "http"
|
|
735
735
|
},
|
|
736
|
-
|
|
736
|
+
411: {
|
|
737
737
|
httpStatus: 411,
|
|
738
738
|
code: "LENGTH_REQUIRED",
|
|
739
739
|
name: "Length Required Error",
|
|
@@ -741,7 +741,7 @@ var http = {
|
|
|
741
741
|
uiMessage: "The request is missing required length information.",
|
|
742
742
|
type: "http"
|
|
743
743
|
},
|
|
744
|
-
|
|
744
|
+
412: {
|
|
745
745
|
httpStatus: 412,
|
|
746
746
|
code: "PRECONDITION_FAILED",
|
|
747
747
|
name: "Precondition Failed Error",
|
|
@@ -749,7 +749,7 @@ var http = {
|
|
|
749
749
|
uiMessage: "A required condition was not met. Please try again.",
|
|
750
750
|
type: "http"
|
|
751
751
|
},
|
|
752
|
-
|
|
752
|
+
413: {
|
|
753
753
|
httpStatus: 413,
|
|
754
754
|
code: "PAYLOAD_TOO_LARGE",
|
|
755
755
|
name: "Payload Too Large Error",
|
|
@@ -757,7 +757,7 @@ var http = {
|
|
|
757
757
|
uiMessage: "The request is too large. Please reduce the size and try again.",
|
|
758
758
|
type: "http"
|
|
759
759
|
},
|
|
760
|
-
|
|
760
|
+
414: {
|
|
761
761
|
httpStatus: 414,
|
|
762
762
|
code: "URI_TOO_LONG",
|
|
763
763
|
name: "URI Too Long Error",
|
|
@@ -765,7 +765,7 @@ var http = {
|
|
|
765
765
|
uiMessage: "The request URL is too long.",
|
|
766
766
|
type: "http"
|
|
767
767
|
},
|
|
768
|
-
|
|
768
|
+
415: {
|
|
769
769
|
httpStatus: 415,
|
|
770
770
|
code: "UNSUPPORTED_MEDIA_TYPE",
|
|
771
771
|
name: "Unsupported Media Type Error",
|
|
@@ -773,7 +773,7 @@ var http = {
|
|
|
773
773
|
uiMessage: "The file type is not supported.",
|
|
774
774
|
type: "http"
|
|
775
775
|
},
|
|
776
|
-
|
|
776
|
+
416: {
|
|
777
777
|
httpStatus: 416,
|
|
778
778
|
code: "RANGE_NOT_SATISFIABLE",
|
|
779
779
|
name: "Range Not Satisfiable Error",
|
|
@@ -781,7 +781,7 @@ var http = {
|
|
|
781
781
|
uiMessage: "The requested range cannot be satisfied.",
|
|
782
782
|
type: "http"
|
|
783
783
|
},
|
|
784
|
-
|
|
784
|
+
417: {
|
|
785
785
|
httpStatus: 417,
|
|
786
786
|
code: "EXPECTATION_FAILED",
|
|
787
787
|
name: "Expectation Failed Error",
|
|
@@ -789,7 +789,7 @@ var http = {
|
|
|
789
789
|
uiMessage: "The server cannot meet the requirements of the request.",
|
|
790
790
|
type: "http"
|
|
791
791
|
},
|
|
792
|
-
|
|
792
|
+
418: {
|
|
793
793
|
httpStatus: 418,
|
|
794
794
|
code: "IM_A_TEAPOT",
|
|
795
795
|
name: "Im A Teapot Error",
|
|
@@ -797,7 +797,7 @@ var http = {
|
|
|
797
797
|
uiMessage: "I'm a teapot and cannot brew coffee.",
|
|
798
798
|
type: "http"
|
|
799
799
|
},
|
|
800
|
-
|
|
800
|
+
422: {
|
|
801
801
|
httpStatus: 422,
|
|
802
802
|
code: "UNPROCESSABLE_ENTITY",
|
|
803
803
|
name: "Unprocessable Entity Error",
|
|
@@ -805,7 +805,7 @@ var http = {
|
|
|
805
805
|
uiMessage: "The request contains invalid data. Please check your input.",
|
|
806
806
|
type: "http"
|
|
807
807
|
},
|
|
808
|
-
|
|
808
|
+
423: {
|
|
809
809
|
httpStatus: 423,
|
|
810
810
|
code: "LOCKED",
|
|
811
811
|
name: "Locked Error",
|
|
@@ -813,7 +813,7 @@ var http = {
|
|
|
813
813
|
uiMessage: "This resource is locked and cannot be modified.",
|
|
814
814
|
type: "http"
|
|
815
815
|
},
|
|
816
|
-
|
|
816
|
+
424: {
|
|
817
817
|
httpStatus: 424,
|
|
818
818
|
code: "FAILED_DEPENDENCY",
|
|
819
819
|
name: "Failed Dependency Error",
|
|
@@ -821,7 +821,7 @@ var http = {
|
|
|
821
821
|
uiMessage: "The request failed due to a dependency error.",
|
|
822
822
|
type: "http"
|
|
823
823
|
},
|
|
824
|
-
|
|
824
|
+
425: {
|
|
825
825
|
httpStatus: 425,
|
|
826
826
|
code: "TOO_EARLY",
|
|
827
827
|
name: "Too Early Error",
|
|
@@ -829,7 +829,7 @@ var http = {
|
|
|
829
829
|
uiMessage: "The request was sent too early. Please try again later.",
|
|
830
830
|
type: "http"
|
|
831
831
|
},
|
|
832
|
-
|
|
832
|
+
426: {
|
|
833
833
|
httpStatus: 426,
|
|
834
834
|
code: "UPGRADE_REQUIRED",
|
|
835
835
|
name: "Upgrade Required Error",
|
|
@@ -837,7 +837,7 @@ var http = {
|
|
|
837
837
|
uiMessage: "Please upgrade to continue using this service.",
|
|
838
838
|
type: "http"
|
|
839
839
|
},
|
|
840
|
-
|
|
840
|
+
428: {
|
|
841
841
|
httpStatus: 428,
|
|
842
842
|
code: "PRECONDITION_REQUIRED",
|
|
843
843
|
name: "Precondition Required Error",
|
|
@@ -845,7 +845,7 @@ var http = {
|
|
|
845
845
|
uiMessage: "Required conditions are missing from the request.",
|
|
846
846
|
type: "http"
|
|
847
847
|
},
|
|
848
|
-
|
|
848
|
+
429: {
|
|
849
849
|
httpStatus: 429,
|
|
850
850
|
code: "TOO_MANY_REQUESTS",
|
|
851
851
|
name: "Too Many Requests Error",
|
|
@@ -853,7 +853,7 @@ var http = {
|
|
|
853
853
|
uiMessage: "You have made too many requests. Please wait and try again.",
|
|
854
854
|
type: "http"
|
|
855
855
|
},
|
|
856
|
-
|
|
856
|
+
431: {
|
|
857
857
|
httpStatus: 431,
|
|
858
858
|
code: "REQUEST_HEADER_FIELDS_TOO_LARGE",
|
|
859
859
|
name: "Request Header Fields Too Large Error",
|
|
@@ -861,7 +861,7 @@ var http = {
|
|
|
861
861
|
uiMessage: "The request headers are too large.",
|
|
862
862
|
type: "http"
|
|
863
863
|
},
|
|
864
|
-
|
|
864
|
+
451: {
|
|
865
865
|
httpStatus: 451,
|
|
866
866
|
code: "UNAVAILABLE_FOR_LEGAL_REASONS",
|
|
867
867
|
name: "Unavailable For Legal Reasons Error",
|
|
@@ -870,7 +870,7 @@ var http = {
|
|
|
870
870
|
type: "http"
|
|
871
871
|
},
|
|
872
872
|
// 5xx Server Errors
|
|
873
|
-
|
|
873
|
+
500: {
|
|
874
874
|
httpStatus: 500,
|
|
875
875
|
code: "INTERNAL_SERVER_ERROR",
|
|
876
876
|
name: "Internal Server Error",
|
|
@@ -878,7 +878,7 @@ var http = {
|
|
|
878
878
|
uiMessage: "An unexpected error occurred. Please try again later.",
|
|
879
879
|
type: "http"
|
|
880
880
|
},
|
|
881
|
-
|
|
881
|
+
501: {
|
|
882
882
|
httpStatus: 501,
|
|
883
883
|
code: "NOT_IMPLEMENTED",
|
|
884
884
|
name: "Not Implemented Error",
|
|
@@ -886,7 +886,7 @@ var http = {
|
|
|
886
886
|
uiMessage: "This feature is not yet available.",
|
|
887
887
|
type: "http"
|
|
888
888
|
},
|
|
889
|
-
|
|
889
|
+
502: {
|
|
890
890
|
httpStatus: 502,
|
|
891
891
|
code: "BAD_GATEWAY",
|
|
892
892
|
name: "Bad Gateway Error",
|
|
@@ -894,7 +894,7 @@ var http = {
|
|
|
894
894
|
uiMessage: "Unable to connect to the server. Please try again later.",
|
|
895
895
|
type: "http"
|
|
896
896
|
},
|
|
897
|
-
|
|
897
|
+
503: {
|
|
898
898
|
httpStatus: 503,
|
|
899
899
|
code: "SERVICE_UNAVAILABLE",
|
|
900
900
|
name: "Service Unavailable Error",
|
|
@@ -902,7 +902,7 @@ var http = {
|
|
|
902
902
|
uiMessage: "The service is temporarily unavailable. Please try again later.",
|
|
903
903
|
type: "http"
|
|
904
904
|
},
|
|
905
|
-
|
|
905
|
+
504: {
|
|
906
906
|
httpStatus: 504,
|
|
907
907
|
code: "GATEWAY_TIMEOUT",
|
|
908
908
|
name: "Gateway Timeout Error",
|
|
@@ -910,7 +910,7 @@ var http = {
|
|
|
910
910
|
uiMessage: "The server took too long to respond. Please try again.",
|
|
911
911
|
type: "http"
|
|
912
912
|
},
|
|
913
|
-
|
|
913
|
+
505: {
|
|
914
914
|
httpStatus: 505,
|
|
915
915
|
code: "HTTP_VERSION_NOT_SUPPORTED",
|
|
916
916
|
name: "HTTP Version Not Supported Error",
|
|
@@ -918,7 +918,7 @@ var http = {
|
|
|
918
918
|
uiMessage: "Your browser version is not supported.",
|
|
919
919
|
type: "http"
|
|
920
920
|
},
|
|
921
|
-
|
|
921
|
+
506: {
|
|
922
922
|
httpStatus: 506,
|
|
923
923
|
code: "VARIANT_ALSO_NEGOTIATES",
|
|
924
924
|
name: "Variant Also Negotiates Error",
|
|
@@ -926,7 +926,7 @@ var http = {
|
|
|
926
926
|
uiMessage: "The server has an internal configuration error.",
|
|
927
927
|
type: "http"
|
|
928
928
|
},
|
|
929
|
-
|
|
929
|
+
507: {
|
|
930
930
|
httpStatus: 507,
|
|
931
931
|
code: "INSUFFICIENT_STORAGE",
|
|
932
932
|
name: "Insufficient Storage Error",
|
|
@@ -934,7 +934,7 @@ var http = {
|
|
|
934
934
|
uiMessage: "The server has insufficient storage to complete the request.",
|
|
935
935
|
type: "http"
|
|
936
936
|
},
|
|
937
|
-
|
|
937
|
+
508: {
|
|
938
938
|
httpStatus: 508,
|
|
939
939
|
code: "LOOP_DETECTED",
|
|
940
940
|
name: "Loop Detected Error",
|
|
@@ -942,7 +942,7 @@ var http = {
|
|
|
942
942
|
uiMessage: "The server detected an infinite loop.",
|
|
943
943
|
type: "http"
|
|
944
944
|
},
|
|
945
|
-
|
|
945
|
+
510: {
|
|
946
946
|
httpStatus: 510,
|
|
947
947
|
code: "NOT_EXTENDED",
|
|
948
948
|
name: "Not Extended Error",
|
|
@@ -950,7 +950,7 @@ var http = {
|
|
|
950
950
|
uiMessage: "Additional extensions are required.",
|
|
951
951
|
type: "http"
|
|
952
952
|
},
|
|
953
|
-
|
|
953
|
+
511: {
|
|
954
954
|
httpStatus: 511,
|
|
955
955
|
code: "NETWORK_AUTHENTICATION_REQUIRED",
|
|
956
956
|
name: "Network Authentication Required Error",
|