@bombillazo/error-x 0.4.3 → 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.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) */
@@ -102,13 +98,12 @@ type ErrorXCause = {
102
98
  * uiMessage: 'Please check your credentials',
103
99
  * stack: 'Error: Authentication failed.\n at login (auth.ts:42:15)',
104
100
  * metadata: { userId: 123, loginAttempt: 3 },
105
- * timestamp: '2024-01-15T10:30:45.123Z',
101
+ * timestamp: 1705315845123,
106
102
  * cause: {
107
103
  * name: 'NetworkError',
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
  * }
@@ -129,16 +124,12 @@ type ErrorXSerialized = {
129
124
  stack?: string;
130
125
  /** Additional context and debugging information */
131
126
  metadata: ErrorXMetadata | undefined;
132
- /** ISO timestamp when error was created */
133
- timestamp: string;
127
+ /** Unix epoch timestamp (milliseconds) when error was created */
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 */
@@ -218,14 +209,10 @@ declare class ErrorX<TMetadata extends ErrorXMetadata = ErrorXMetadata> extends
218
209
  uiMessage: string | undefined;
219
210
  /** Additional context and metadata associated with the error */
220
211
  metadata: TMetadata | undefined;
221
- /** Timestamp when the error was created */
222
- timestamp: Date;
223
- /** HTTP status code (100-599) for HTTP-related errors */
224
- httpStatus: number | undefined;
212
+ /** Unix epoch timestamp (milliseconds) when the error was created */
213
+ timestamp: number;
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
  *
@@ -400,7 +380,7 @@ declare class ErrorX<TMetadata extends ErrorXMetadata = ErrorXMetadata> extends
400
380
  * // Result: metadata = { endpoint: '/users', retryCount: 3, userId: 123 }
401
381
  * ```
402
382
  */
403
- withMetadata(additionalMetadata: Partial<TMetadata>): ErrorX<TMetadata>;
383
+ withMetadata<TAdditionalMetadata extends Record<string, unknown> = ErrorXMetadata>(additionalMetadata: TAdditionalMetadata): ErrorX<TMetadata & TAdditionalMetadata>;
404
384
  /**
405
385
  * Type guard that checks if a value is an ErrorX instance.
406
386
  *
@@ -474,7 +454,7 @@ declare class ErrorX<TMetadata extends ErrorXMetadata = ErrorXMetadata> extends
474
454
  * })
475
455
  *
476
456
  * console.log(error.toString())
477
- * // Output: "DatabaseError: Database connection failed. [DB_CONN_FAILED] (2024-01-15T10:30:45.123Z) metadata: {...}"
457
+ * // Output: "DatabaseError: Database connection failed. [DB_CONN_FAILED] 2025-01-15T10:30:45.123Z (1736937045123) metadata: {...}"
478
458
  * ```
479
459
  */
480
460
  toString(): string;
@@ -512,7 +492,7 @@ declare class ErrorX<TMetadata extends ErrorXMetadata = ErrorXMetadata> extends
512
492
  * code: 'DB_CONN_FAILED',
513
493
  * uiMessage: 'Database is temporarily unavailable',
514
494
  * metadata: { host: 'localhost' },
515
- * timestamp: '2024-01-15T10:30:45.123Z'
495
+ * timestamp: 1705315845123
516
496
  * }
517
497
  *
518
498
  * const error = ErrorX.fromJSON(serializedError)
@@ -631,316 +611,355 @@ declare class ErrorX<TMetadata extends ErrorXMetadata = ErrorXMetadata> extends
631
611
  */
632
612
  declare const http: {
633
613
  readonly 400: {
634
- httpStatus: number;
635
614
  code: string;
636
615
  name: string;
637
616
  message: string;
638
617
  uiMessage: string;
639
- type: string;
618
+ metadata: {
619
+ status: number;
620
+ };
640
621
  };
641
622
  readonly 401: {
642
- httpStatus: number;
643
623
  code: string;
644
624
  name: string;
645
625
  message: string;
646
626
  uiMessage: string;
647
- type: string;
627
+ metadata: {
628
+ status: number;
629
+ };
648
630
  };
649
631
  readonly 402: {
650
- httpStatus: number;
651
632
  code: string;
652
633
  name: string;
653
634
  message: string;
654
635
  uiMessage: string;
655
- type: string;
636
+ metadata: {
637
+ status: number;
638
+ };
656
639
  };
657
640
  readonly 403: {
658
- httpStatus: number;
659
641
  code: string;
660
642
  name: string;
661
643
  message: string;
662
644
  uiMessage: string;
663
- type: string;
645
+ metadata: {
646
+ status: number;
647
+ };
664
648
  };
665
649
  readonly 404: {
666
- httpStatus: number;
667
650
  code: string;
668
651
  name: string;
669
652
  message: string;
670
653
  uiMessage: string;
671
- type: string;
654
+ metadata: {
655
+ status: number;
656
+ };
672
657
  };
673
658
  readonly 405: {
674
- httpStatus: number;
675
659
  code: string;
676
660
  name: string;
677
661
  message: string;
678
662
  uiMessage: string;
679
- type: string;
663
+ metadata: {
664
+ status: number;
665
+ };
680
666
  };
681
667
  readonly 406: {
682
- httpStatus: number;
683
668
  code: string;
684
669
  name: string;
685
670
  message: string;
686
671
  uiMessage: string;
687
- type: string;
672
+ metadata: {
673
+ status: number;
674
+ };
688
675
  };
689
676
  readonly 407: {
690
- httpStatus: number;
691
677
  code: string;
692
678
  name: string;
693
679
  message: string;
694
680
  uiMessage: string;
695
- type: string;
681
+ metadata: {
682
+ status: number;
683
+ };
696
684
  };
697
685
  readonly 408: {
698
- httpStatus: number;
699
686
  code: string;
700
687
  name: string;
701
688
  message: string;
702
689
  uiMessage: string;
703
- type: string;
690
+ metadata: {
691
+ status: number;
692
+ };
704
693
  };
705
694
  readonly 409: {
706
- httpStatus: number;
707
695
  code: string;
708
696
  name: string;
709
697
  message: string;
710
698
  uiMessage: string;
711
- type: string;
699
+ metadata: {
700
+ status: number;
701
+ };
712
702
  };
713
703
  readonly 410: {
714
- httpStatus: number;
715
704
  code: string;
716
705
  name: string;
717
706
  message: string;
718
707
  uiMessage: string;
719
- type: string;
708
+ metadata: {
709
+ status: number;
710
+ };
720
711
  };
721
712
  readonly 411: {
722
- httpStatus: number;
723
713
  code: string;
724
714
  name: string;
725
715
  message: string;
726
716
  uiMessage: string;
727
- type: string;
717
+ metadata: {
718
+ status: number;
719
+ };
728
720
  };
729
721
  readonly 412: {
730
- httpStatus: number;
731
722
  code: string;
732
723
  name: string;
733
724
  message: string;
734
725
  uiMessage: string;
735
- type: string;
726
+ metadata: {
727
+ status: number;
728
+ };
736
729
  };
737
730
  readonly 413: {
738
- httpStatus: number;
739
731
  code: string;
740
732
  name: string;
741
733
  message: string;
742
734
  uiMessage: string;
743
- type: string;
735
+ metadata: {
736
+ status: number;
737
+ };
744
738
  };
745
739
  readonly 414: {
746
- httpStatus: number;
747
740
  code: string;
748
741
  name: string;
749
742
  message: string;
750
743
  uiMessage: string;
751
- type: string;
744
+ metadata: {
745
+ status: number;
746
+ };
752
747
  };
753
748
  readonly 415: {
754
- httpStatus: number;
755
749
  code: string;
756
750
  name: string;
757
751
  message: string;
758
752
  uiMessage: string;
759
- type: string;
753
+ metadata: {
754
+ status: number;
755
+ };
760
756
  };
761
757
  readonly 416: {
762
- httpStatus: number;
763
758
  code: string;
764
759
  name: string;
765
760
  message: string;
766
761
  uiMessage: string;
767
- type: string;
762
+ metadata: {
763
+ status: number;
764
+ };
768
765
  };
769
766
  readonly 417: {
770
- httpStatus: number;
771
767
  code: string;
772
768
  name: string;
773
769
  message: string;
774
770
  uiMessage: string;
775
- type: string;
771
+ metadata: {
772
+ status: number;
773
+ };
776
774
  };
777
775
  readonly 418: {
778
- httpStatus: number;
779
776
  code: string;
780
777
  name: string;
781
778
  message: string;
782
779
  uiMessage: string;
783
- type: string;
780
+ metadata: {
781
+ status: number;
782
+ };
784
783
  };
785
784
  readonly 422: {
786
- httpStatus: number;
787
785
  code: string;
788
786
  name: string;
789
787
  message: string;
790
788
  uiMessage: string;
791
- type: string;
789
+ metadata: {
790
+ status: number;
791
+ };
792
792
  };
793
793
  readonly 423: {
794
- httpStatus: number;
795
794
  code: string;
796
795
  name: string;
797
796
  message: string;
798
797
  uiMessage: string;
799
- type: string;
798
+ metadata: {
799
+ status: number;
800
+ };
800
801
  };
801
802
  readonly 424: {
802
- httpStatus: number;
803
803
  code: string;
804
804
  name: string;
805
805
  message: string;
806
806
  uiMessage: string;
807
- type: string;
807
+ metadata: {
808
+ status: number;
809
+ };
808
810
  };
809
811
  readonly 425: {
810
- httpStatus: number;
811
812
  code: string;
812
813
  name: string;
813
814
  message: string;
814
815
  uiMessage: string;
815
- type: string;
816
+ metadata: {
817
+ status: number;
818
+ };
816
819
  };
817
820
  readonly 426: {
818
- httpStatus: number;
819
821
  code: string;
820
822
  name: string;
821
823
  message: string;
822
824
  uiMessage: string;
823
- type: string;
825
+ metadata: {
826
+ status: number;
827
+ };
824
828
  };
825
829
  readonly 428: {
826
- httpStatus: number;
827
830
  code: string;
828
831
  name: string;
829
832
  message: string;
830
833
  uiMessage: string;
831
- type: string;
834
+ metadata: {
835
+ status: number;
836
+ };
832
837
  };
833
838
  readonly 429: {
834
- httpStatus: number;
835
839
  code: string;
836
840
  name: string;
837
841
  message: string;
838
842
  uiMessage: string;
839
- type: string;
843
+ metadata: {
844
+ status: number;
845
+ };
840
846
  };
841
847
  readonly 431: {
842
- httpStatus: number;
843
848
  code: string;
844
849
  name: string;
845
850
  message: string;
846
851
  uiMessage: string;
847
- type: string;
852
+ metadata: {
853
+ status: number;
854
+ };
848
855
  };
849
856
  readonly 451: {
850
- httpStatus: number;
851
857
  code: string;
852
858
  name: string;
853
859
  message: string;
854
860
  uiMessage: string;
855
- type: string;
861
+ metadata: {
862
+ status: number;
863
+ };
856
864
  };
857
865
  readonly 500: {
858
- httpStatus: number;
859
866
  code: string;
860
867
  name: string;
861
868
  message: string;
862
869
  uiMessage: string;
863
- type: string;
870
+ metadata: {
871
+ status: number;
872
+ };
864
873
  };
865
874
  readonly 501: {
866
- httpStatus: number;
867
875
  code: string;
868
876
  name: string;
869
877
  message: string;
870
878
  uiMessage: string;
871
- type: string;
879
+ metadata: {
880
+ status: number;
881
+ };
872
882
  };
873
883
  readonly 502: {
874
- httpStatus: number;
875
884
  code: string;
876
885
  name: string;
877
886
  message: string;
878
887
  uiMessage: string;
879
- type: string;
888
+ metadata: {
889
+ status: number;
890
+ };
880
891
  };
881
892
  readonly 503: {
882
- httpStatus: number;
883
893
  code: string;
884
894
  name: string;
885
895
  message: string;
886
896
  uiMessage: string;
887
- type: string;
897
+ metadata: {
898
+ status: number;
899
+ };
888
900
  };
889
901
  readonly 504: {
890
- httpStatus: number;
891
902
  code: string;
892
903
  name: string;
893
904
  message: string;
894
905
  uiMessage: string;
895
- type: string;
906
+ metadata: {
907
+ status: number;
908
+ };
896
909
  };
897
910
  readonly 505: {
898
- httpStatus: number;
899
911
  code: string;
900
912
  name: string;
901
913
  message: string;
902
914
  uiMessage: string;
903
- type: string;
915
+ metadata: {
916
+ status: number;
917
+ };
904
918
  };
905
919
  readonly 506: {
906
- httpStatus: number;
907
920
  code: string;
908
921
  name: string;
909
922
  message: string;
910
923
  uiMessage: string;
911
- type: string;
924
+ metadata: {
925
+ status: number;
926
+ };
912
927
  };
913
928
  readonly 507: {
914
- httpStatus: number;
915
929
  code: string;
916
930
  name: string;
917
931
  message: string;
918
932
  uiMessage: string;
919
- type: string;
933
+ metadata: {
934
+ status: number;
935
+ };
920
936
  };
921
937
  readonly 508: {
922
- httpStatus: number;
923
938
  code: string;
924
939
  name: string;
925
940
  message: string;
926
941
  uiMessage: string;
927
- type: string;
942
+ metadata: {
943
+ status: number;
944
+ };
928
945
  };
929
946
  readonly 510: {
930
- httpStatus: number;
931
947
  code: string;
932
948
  name: string;
933
949
  message: string;
934
950
  uiMessage: string;
935
- type: string;
951
+ metadata: {
952
+ status: number;
953
+ };
936
954
  };
937
955
  readonly 511: {
938
- httpStatus: number;
939
956
  code: string;
940
957
  name: string;
941
958
  message: string;
942
959
  uiMessage: string;
943
- type: string;
960
+ metadata: {
961
+ status: number;
962
+ };
944
963
  };
945
964
  };
946
965