@bombillazo/error-x 0.4.4 → 0.4.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.
- package/README.md +11 -128
- package/dist/index.cjs +44 -136
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +122 -100
- package/dist/index.d.ts +122 -100
- package/dist/index.js +44 -136
- package/dist/index.js.map +1 -1
- package/package.json +47 -42
package/dist/index.d.cts
CHANGED
|
@@ -64,12 +64,8 @@ type ErrorXOptions<TMetadata extends ErrorXMetadata = ErrorXMetadata> = {
|
|
|
64
64
|
cause?: ErrorXCause | Error | unknown;
|
|
65
65
|
/** Additional context and debugging information */
|
|
66
66
|
metadata?: TMetadata | undefined;
|
|
67
|
-
/** HTTP status code (100-599) for HTTP-related errors */
|
|
68
|
-
httpStatus?: number | undefined;
|
|
69
67
|
/** Error type for categorization */
|
|
70
68
|
type?: string | undefined;
|
|
71
|
-
/** Source URL related to the error (API endpoint, page URL, resource URL) */
|
|
72
|
-
sourceUrl?: string | undefined;
|
|
73
69
|
/** Documentation URL for this specific error */
|
|
74
70
|
docsUrl?: string | undefined;
|
|
75
71
|
/** Where the error originated (service name, module, component) */
|
|
@@ -108,7 +104,6 @@ type ErrorXCause = {
|
|
|
108
104
|
* message: 'Request timeout.',
|
|
109
105
|
* stack: '...'
|
|
110
106
|
* },
|
|
111
|
-
* sourceUrl: 'https://api.example.com/auth',
|
|
112
107
|
* docsUrl: 'https://docs.example.com/errors#auth-failed',
|
|
113
108
|
* source: 'auth-service'
|
|
114
109
|
* }
|
|
@@ -133,12 +128,8 @@ type ErrorXSerialized = {
|
|
|
133
128
|
timestamp: number;
|
|
134
129
|
/** Simplified cause error (for error chaining) */
|
|
135
130
|
cause?: ErrorXCause;
|
|
136
|
-
/** HTTP status code for HTTP-related errors */
|
|
137
|
-
httpStatus?: number;
|
|
138
131
|
/** Error type for categorization */
|
|
139
132
|
type?: string;
|
|
140
|
-
/** Source URL related to the error */
|
|
141
|
-
sourceUrl?: string;
|
|
142
133
|
/** Documentation URL for this error */
|
|
143
134
|
docsUrl?: string;
|
|
144
135
|
/** Where the error originated */
|
|
@@ -220,12 +211,8 @@ declare class ErrorX<TMetadata extends ErrorXMetadata = ErrorXMetadata> extends
|
|
|
220
211
|
metadata: TMetadata | undefined;
|
|
221
212
|
/** Unix epoch timestamp (milliseconds) when the error was created */
|
|
222
213
|
timestamp: number;
|
|
223
|
-
/** HTTP status code (100-599) for HTTP-related errors */
|
|
224
|
-
httpStatus: number | undefined;
|
|
225
214
|
/** Error type for categorization */
|
|
226
215
|
type: string | undefined;
|
|
227
|
-
/** Source URL related to the error (API endpoint, page URL, resource URL) */
|
|
228
|
-
sourceUrl: string | undefined;
|
|
229
216
|
/** Documentation URL for this specific error */
|
|
230
217
|
docsUrl: string | undefined;
|
|
231
218
|
/** Where the error originated (service name, module, component) */
|
|
@@ -314,13 +301,6 @@ declare class ErrorX<TMetadata extends ErrorXMetadata = ErrorXMetadata> extends
|
|
|
314
301
|
* ```
|
|
315
302
|
*/
|
|
316
303
|
static resetConfig(): void;
|
|
317
|
-
/**
|
|
318
|
-
* Validates HTTP status code to ensure it's within valid range (100-599)
|
|
319
|
-
*
|
|
320
|
-
* @param status - Status code to validate
|
|
321
|
-
* @returns Valid status code or undefined if invalid/not provided
|
|
322
|
-
*/
|
|
323
|
-
private static validateHttpStatus;
|
|
324
304
|
/**
|
|
325
305
|
* Validates and normalizes the type field
|
|
326
306
|
*
|
|
@@ -423,7 +403,8 @@ declare class ErrorX<TMetadata extends ErrorXMetadata = ErrorXMetadata> extends
|
|
|
423
403
|
/**
|
|
424
404
|
* Converts unknown input into ErrorXOptions with intelligent property extraction.
|
|
425
405
|
* Handles strings, regular Error objects, API response objects, and unknown values.
|
|
426
|
-
*
|
|
406
|
+
* Extracts metadata directly from objects if present, without wrapping.
|
|
407
|
+
* This is a private helper method used by ErrorX.from().
|
|
427
408
|
*
|
|
428
409
|
* @param error - Value to convert to ErrorXOptions
|
|
429
410
|
* @returns ErrorXOptions object with extracted properties
|
|
@@ -433,6 +414,7 @@ declare class ErrorX<TMetadata extends ErrorXMetadata = ErrorXMetadata> extends
|
|
|
433
414
|
/**
|
|
434
415
|
* Converts unknown input into an ErrorX instance with intelligent property extraction.
|
|
435
416
|
* Handles strings, regular Error objects, API response objects, and unknown values.
|
|
417
|
+
* Extracts metadata directly from objects if present.
|
|
436
418
|
*
|
|
437
419
|
* @param error - Value to convert to ErrorX
|
|
438
420
|
* @returns ErrorX instance with extracted properties
|
|
@@ -449,9 +431,10 @@ declare class ErrorX<TMetadata extends ErrorXMetadata = ErrorXMetadata> extends
|
|
|
449
431
|
* const apiError = {
|
|
450
432
|
* message: 'User not found',
|
|
451
433
|
* code: 'USER_404',
|
|
452
|
-
*
|
|
434
|
+
* metadata: { userId: 123, endpoint: '/api/users' }
|
|
453
435
|
* }
|
|
454
436
|
* const error3 = ErrorX.from(apiError)
|
|
437
|
+
* // error3.metadata = { userId: 123, endpoint: '/api/users' }
|
|
455
438
|
* ```
|
|
456
439
|
*/
|
|
457
440
|
static from<TMetadata extends ErrorXMetadata = ErrorXMetadata>(error: ErrorX<TMetadata>): ErrorX<TMetadata>;
|
|
@@ -631,316 +614,355 @@ declare class ErrorX<TMetadata extends ErrorXMetadata = ErrorXMetadata> extends
|
|
|
631
614
|
*/
|
|
632
615
|
declare const http: {
|
|
633
616
|
readonly 400: {
|
|
634
|
-
httpStatus: number;
|
|
635
617
|
code: string;
|
|
636
618
|
name: string;
|
|
637
619
|
message: string;
|
|
638
620
|
uiMessage: string;
|
|
639
|
-
|
|
621
|
+
metadata: {
|
|
622
|
+
status: number;
|
|
623
|
+
};
|
|
640
624
|
};
|
|
641
625
|
readonly 401: {
|
|
642
|
-
httpStatus: number;
|
|
643
626
|
code: string;
|
|
644
627
|
name: string;
|
|
645
628
|
message: string;
|
|
646
629
|
uiMessage: string;
|
|
647
|
-
|
|
630
|
+
metadata: {
|
|
631
|
+
status: number;
|
|
632
|
+
};
|
|
648
633
|
};
|
|
649
634
|
readonly 402: {
|
|
650
|
-
httpStatus: number;
|
|
651
635
|
code: string;
|
|
652
636
|
name: string;
|
|
653
637
|
message: string;
|
|
654
638
|
uiMessage: string;
|
|
655
|
-
|
|
639
|
+
metadata: {
|
|
640
|
+
status: number;
|
|
641
|
+
};
|
|
656
642
|
};
|
|
657
643
|
readonly 403: {
|
|
658
|
-
httpStatus: number;
|
|
659
644
|
code: string;
|
|
660
645
|
name: string;
|
|
661
646
|
message: string;
|
|
662
647
|
uiMessage: string;
|
|
663
|
-
|
|
648
|
+
metadata: {
|
|
649
|
+
status: number;
|
|
650
|
+
};
|
|
664
651
|
};
|
|
665
652
|
readonly 404: {
|
|
666
|
-
httpStatus: number;
|
|
667
653
|
code: string;
|
|
668
654
|
name: string;
|
|
669
655
|
message: string;
|
|
670
656
|
uiMessage: string;
|
|
671
|
-
|
|
657
|
+
metadata: {
|
|
658
|
+
status: number;
|
|
659
|
+
};
|
|
672
660
|
};
|
|
673
661
|
readonly 405: {
|
|
674
|
-
httpStatus: number;
|
|
675
662
|
code: string;
|
|
676
663
|
name: string;
|
|
677
664
|
message: string;
|
|
678
665
|
uiMessage: string;
|
|
679
|
-
|
|
666
|
+
metadata: {
|
|
667
|
+
status: number;
|
|
668
|
+
};
|
|
680
669
|
};
|
|
681
670
|
readonly 406: {
|
|
682
|
-
httpStatus: number;
|
|
683
671
|
code: string;
|
|
684
672
|
name: string;
|
|
685
673
|
message: string;
|
|
686
674
|
uiMessage: string;
|
|
687
|
-
|
|
675
|
+
metadata: {
|
|
676
|
+
status: number;
|
|
677
|
+
};
|
|
688
678
|
};
|
|
689
679
|
readonly 407: {
|
|
690
|
-
httpStatus: number;
|
|
691
680
|
code: string;
|
|
692
681
|
name: string;
|
|
693
682
|
message: string;
|
|
694
683
|
uiMessage: string;
|
|
695
|
-
|
|
684
|
+
metadata: {
|
|
685
|
+
status: number;
|
|
686
|
+
};
|
|
696
687
|
};
|
|
697
688
|
readonly 408: {
|
|
698
|
-
httpStatus: number;
|
|
699
689
|
code: string;
|
|
700
690
|
name: string;
|
|
701
691
|
message: string;
|
|
702
692
|
uiMessage: string;
|
|
703
|
-
|
|
693
|
+
metadata: {
|
|
694
|
+
status: number;
|
|
695
|
+
};
|
|
704
696
|
};
|
|
705
697
|
readonly 409: {
|
|
706
|
-
httpStatus: number;
|
|
707
698
|
code: string;
|
|
708
699
|
name: string;
|
|
709
700
|
message: string;
|
|
710
701
|
uiMessage: string;
|
|
711
|
-
|
|
702
|
+
metadata: {
|
|
703
|
+
status: number;
|
|
704
|
+
};
|
|
712
705
|
};
|
|
713
706
|
readonly 410: {
|
|
714
|
-
httpStatus: number;
|
|
715
707
|
code: string;
|
|
716
708
|
name: string;
|
|
717
709
|
message: string;
|
|
718
710
|
uiMessage: string;
|
|
719
|
-
|
|
711
|
+
metadata: {
|
|
712
|
+
status: number;
|
|
713
|
+
};
|
|
720
714
|
};
|
|
721
715
|
readonly 411: {
|
|
722
|
-
httpStatus: number;
|
|
723
716
|
code: string;
|
|
724
717
|
name: string;
|
|
725
718
|
message: string;
|
|
726
719
|
uiMessage: string;
|
|
727
|
-
|
|
720
|
+
metadata: {
|
|
721
|
+
status: number;
|
|
722
|
+
};
|
|
728
723
|
};
|
|
729
724
|
readonly 412: {
|
|
730
|
-
httpStatus: number;
|
|
731
725
|
code: string;
|
|
732
726
|
name: string;
|
|
733
727
|
message: string;
|
|
734
728
|
uiMessage: string;
|
|
735
|
-
|
|
729
|
+
metadata: {
|
|
730
|
+
status: number;
|
|
731
|
+
};
|
|
736
732
|
};
|
|
737
733
|
readonly 413: {
|
|
738
|
-
httpStatus: number;
|
|
739
734
|
code: string;
|
|
740
735
|
name: string;
|
|
741
736
|
message: string;
|
|
742
737
|
uiMessage: string;
|
|
743
|
-
|
|
738
|
+
metadata: {
|
|
739
|
+
status: number;
|
|
740
|
+
};
|
|
744
741
|
};
|
|
745
742
|
readonly 414: {
|
|
746
|
-
httpStatus: number;
|
|
747
743
|
code: string;
|
|
748
744
|
name: string;
|
|
749
745
|
message: string;
|
|
750
746
|
uiMessage: string;
|
|
751
|
-
|
|
747
|
+
metadata: {
|
|
748
|
+
status: number;
|
|
749
|
+
};
|
|
752
750
|
};
|
|
753
751
|
readonly 415: {
|
|
754
|
-
httpStatus: number;
|
|
755
752
|
code: string;
|
|
756
753
|
name: string;
|
|
757
754
|
message: string;
|
|
758
755
|
uiMessage: string;
|
|
759
|
-
|
|
756
|
+
metadata: {
|
|
757
|
+
status: number;
|
|
758
|
+
};
|
|
760
759
|
};
|
|
761
760
|
readonly 416: {
|
|
762
|
-
httpStatus: number;
|
|
763
761
|
code: string;
|
|
764
762
|
name: string;
|
|
765
763
|
message: string;
|
|
766
764
|
uiMessage: string;
|
|
767
|
-
|
|
765
|
+
metadata: {
|
|
766
|
+
status: number;
|
|
767
|
+
};
|
|
768
768
|
};
|
|
769
769
|
readonly 417: {
|
|
770
|
-
httpStatus: number;
|
|
771
770
|
code: string;
|
|
772
771
|
name: string;
|
|
773
772
|
message: string;
|
|
774
773
|
uiMessage: string;
|
|
775
|
-
|
|
774
|
+
metadata: {
|
|
775
|
+
status: number;
|
|
776
|
+
};
|
|
776
777
|
};
|
|
777
778
|
readonly 418: {
|
|
778
|
-
httpStatus: number;
|
|
779
779
|
code: string;
|
|
780
780
|
name: string;
|
|
781
781
|
message: string;
|
|
782
782
|
uiMessage: string;
|
|
783
|
-
|
|
783
|
+
metadata: {
|
|
784
|
+
status: number;
|
|
785
|
+
};
|
|
784
786
|
};
|
|
785
787
|
readonly 422: {
|
|
786
|
-
httpStatus: number;
|
|
787
788
|
code: string;
|
|
788
789
|
name: string;
|
|
789
790
|
message: string;
|
|
790
791
|
uiMessage: string;
|
|
791
|
-
|
|
792
|
+
metadata: {
|
|
793
|
+
status: number;
|
|
794
|
+
};
|
|
792
795
|
};
|
|
793
796
|
readonly 423: {
|
|
794
|
-
httpStatus: number;
|
|
795
797
|
code: string;
|
|
796
798
|
name: string;
|
|
797
799
|
message: string;
|
|
798
800
|
uiMessage: string;
|
|
799
|
-
|
|
801
|
+
metadata: {
|
|
802
|
+
status: number;
|
|
803
|
+
};
|
|
800
804
|
};
|
|
801
805
|
readonly 424: {
|
|
802
|
-
httpStatus: number;
|
|
803
806
|
code: string;
|
|
804
807
|
name: string;
|
|
805
808
|
message: string;
|
|
806
809
|
uiMessage: string;
|
|
807
|
-
|
|
810
|
+
metadata: {
|
|
811
|
+
status: number;
|
|
812
|
+
};
|
|
808
813
|
};
|
|
809
814
|
readonly 425: {
|
|
810
|
-
httpStatus: number;
|
|
811
815
|
code: string;
|
|
812
816
|
name: string;
|
|
813
817
|
message: string;
|
|
814
818
|
uiMessage: string;
|
|
815
|
-
|
|
819
|
+
metadata: {
|
|
820
|
+
status: number;
|
|
821
|
+
};
|
|
816
822
|
};
|
|
817
823
|
readonly 426: {
|
|
818
|
-
httpStatus: number;
|
|
819
824
|
code: string;
|
|
820
825
|
name: string;
|
|
821
826
|
message: string;
|
|
822
827
|
uiMessage: string;
|
|
823
|
-
|
|
828
|
+
metadata: {
|
|
829
|
+
status: number;
|
|
830
|
+
};
|
|
824
831
|
};
|
|
825
832
|
readonly 428: {
|
|
826
|
-
httpStatus: number;
|
|
827
833
|
code: string;
|
|
828
834
|
name: string;
|
|
829
835
|
message: string;
|
|
830
836
|
uiMessage: string;
|
|
831
|
-
|
|
837
|
+
metadata: {
|
|
838
|
+
status: number;
|
|
839
|
+
};
|
|
832
840
|
};
|
|
833
841
|
readonly 429: {
|
|
834
|
-
httpStatus: number;
|
|
835
842
|
code: string;
|
|
836
843
|
name: string;
|
|
837
844
|
message: string;
|
|
838
845
|
uiMessage: string;
|
|
839
|
-
|
|
846
|
+
metadata: {
|
|
847
|
+
status: number;
|
|
848
|
+
};
|
|
840
849
|
};
|
|
841
850
|
readonly 431: {
|
|
842
|
-
httpStatus: number;
|
|
843
851
|
code: string;
|
|
844
852
|
name: string;
|
|
845
853
|
message: string;
|
|
846
854
|
uiMessage: string;
|
|
847
|
-
|
|
855
|
+
metadata: {
|
|
856
|
+
status: number;
|
|
857
|
+
};
|
|
848
858
|
};
|
|
849
859
|
readonly 451: {
|
|
850
|
-
httpStatus: number;
|
|
851
860
|
code: string;
|
|
852
861
|
name: string;
|
|
853
862
|
message: string;
|
|
854
863
|
uiMessage: string;
|
|
855
|
-
|
|
864
|
+
metadata: {
|
|
865
|
+
status: number;
|
|
866
|
+
};
|
|
856
867
|
};
|
|
857
868
|
readonly 500: {
|
|
858
|
-
httpStatus: number;
|
|
859
869
|
code: string;
|
|
860
870
|
name: string;
|
|
861
871
|
message: string;
|
|
862
872
|
uiMessage: string;
|
|
863
|
-
|
|
873
|
+
metadata: {
|
|
874
|
+
status: number;
|
|
875
|
+
};
|
|
864
876
|
};
|
|
865
877
|
readonly 501: {
|
|
866
|
-
httpStatus: number;
|
|
867
878
|
code: string;
|
|
868
879
|
name: string;
|
|
869
880
|
message: string;
|
|
870
881
|
uiMessage: string;
|
|
871
|
-
|
|
882
|
+
metadata: {
|
|
883
|
+
status: number;
|
|
884
|
+
};
|
|
872
885
|
};
|
|
873
886
|
readonly 502: {
|
|
874
|
-
httpStatus: number;
|
|
875
887
|
code: string;
|
|
876
888
|
name: string;
|
|
877
889
|
message: string;
|
|
878
890
|
uiMessage: string;
|
|
879
|
-
|
|
891
|
+
metadata: {
|
|
892
|
+
status: number;
|
|
893
|
+
};
|
|
880
894
|
};
|
|
881
895
|
readonly 503: {
|
|
882
|
-
httpStatus: number;
|
|
883
896
|
code: string;
|
|
884
897
|
name: string;
|
|
885
898
|
message: string;
|
|
886
899
|
uiMessage: string;
|
|
887
|
-
|
|
900
|
+
metadata: {
|
|
901
|
+
status: number;
|
|
902
|
+
};
|
|
888
903
|
};
|
|
889
904
|
readonly 504: {
|
|
890
|
-
httpStatus: number;
|
|
891
905
|
code: string;
|
|
892
906
|
name: string;
|
|
893
907
|
message: string;
|
|
894
908
|
uiMessage: string;
|
|
895
|
-
|
|
909
|
+
metadata: {
|
|
910
|
+
status: number;
|
|
911
|
+
};
|
|
896
912
|
};
|
|
897
913
|
readonly 505: {
|
|
898
|
-
httpStatus: number;
|
|
899
914
|
code: string;
|
|
900
915
|
name: string;
|
|
901
916
|
message: string;
|
|
902
917
|
uiMessage: string;
|
|
903
|
-
|
|
918
|
+
metadata: {
|
|
919
|
+
status: number;
|
|
920
|
+
};
|
|
904
921
|
};
|
|
905
922
|
readonly 506: {
|
|
906
|
-
httpStatus: number;
|
|
907
923
|
code: string;
|
|
908
924
|
name: string;
|
|
909
925
|
message: string;
|
|
910
926
|
uiMessage: string;
|
|
911
|
-
|
|
927
|
+
metadata: {
|
|
928
|
+
status: number;
|
|
929
|
+
};
|
|
912
930
|
};
|
|
913
931
|
readonly 507: {
|
|
914
|
-
httpStatus: number;
|
|
915
932
|
code: string;
|
|
916
933
|
name: string;
|
|
917
934
|
message: string;
|
|
918
935
|
uiMessage: string;
|
|
919
|
-
|
|
936
|
+
metadata: {
|
|
937
|
+
status: number;
|
|
938
|
+
};
|
|
920
939
|
};
|
|
921
940
|
readonly 508: {
|
|
922
|
-
httpStatus: number;
|
|
923
941
|
code: string;
|
|
924
942
|
name: string;
|
|
925
943
|
message: string;
|
|
926
944
|
uiMessage: string;
|
|
927
|
-
|
|
945
|
+
metadata: {
|
|
946
|
+
status: number;
|
|
947
|
+
};
|
|
928
948
|
};
|
|
929
949
|
readonly 510: {
|
|
930
|
-
httpStatus: number;
|
|
931
950
|
code: string;
|
|
932
951
|
name: string;
|
|
933
952
|
message: string;
|
|
934
953
|
uiMessage: string;
|
|
935
|
-
|
|
954
|
+
metadata: {
|
|
955
|
+
status: number;
|
|
956
|
+
};
|
|
936
957
|
};
|
|
937
958
|
readonly 511: {
|
|
938
|
-
httpStatus: number;
|
|
939
959
|
code: string;
|
|
940
960
|
name: string;
|
|
941
961
|
message: string;
|
|
942
962
|
uiMessage: string;
|
|
943
|
-
|
|
963
|
+
metadata: {
|
|
964
|
+
status: number;
|
|
965
|
+
};
|
|
944
966
|
};
|
|
945
967
|
};
|
|
946
968
|
|