@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/dist/index.d.ts CHANGED
@@ -102,7 +102,7 @@ type ErrorXCause = {
102
102
  * uiMessage: 'Please check your credentials',
103
103
  * stack: 'Error: Authentication failed.\n at login (auth.ts:42:15)',
104
104
  * metadata: { userId: 123, loginAttempt: 3 },
105
- * timestamp: '2024-01-15T10:30:45.123Z',
105
+ * timestamp: 1705315845123,
106
106
  * cause: {
107
107
  * name: 'NetworkError',
108
108
  * message: 'Request timeout.',
@@ -129,8 +129,8 @@ type ErrorXSerialized = {
129
129
  stack?: string;
130
130
  /** Additional context and debugging information */
131
131
  metadata: ErrorXMetadata | undefined;
132
- /** ISO timestamp when error was created */
133
- timestamp: string;
132
+ /** Unix epoch timestamp (milliseconds) when error was created */
133
+ timestamp: number;
134
134
  /** Simplified cause error (for error chaining) */
135
135
  cause?: ErrorXCause;
136
136
  /** HTTP status code for HTTP-related errors */
@@ -218,8 +218,8 @@ declare class ErrorX<TMetadata extends ErrorXMetadata = ErrorXMetadata> extends
218
218
  uiMessage: string | undefined;
219
219
  /** Additional context and metadata associated with the error */
220
220
  metadata: TMetadata | undefined;
221
- /** Timestamp when the error was created */
222
- timestamp: Date;
221
+ /** Unix epoch timestamp (milliseconds) when the error was created */
222
+ timestamp: number;
223
223
  /** HTTP status code (100-599) for HTTP-related errors */
224
224
  httpStatus: number | undefined;
225
225
  /** Error type for categorization */
@@ -400,7 +400,7 @@ declare class ErrorX<TMetadata extends ErrorXMetadata = ErrorXMetadata> extends
400
400
  * // Result: metadata = { endpoint: '/users', retryCount: 3, userId: 123 }
401
401
  * ```
402
402
  */
403
- withMetadata(additionalMetadata: Partial<TMetadata>): ErrorX<TMetadata>;
403
+ withMetadata<TAdditionalMetadata extends Record<string, unknown> = ErrorXMetadata>(additionalMetadata: TAdditionalMetadata): ErrorX<TMetadata & TAdditionalMetadata>;
404
404
  /**
405
405
  * Type guard that checks if a value is an ErrorX instance.
406
406
  *
@@ -474,7 +474,7 @@ declare class ErrorX<TMetadata extends ErrorXMetadata = ErrorXMetadata> extends
474
474
  * })
475
475
  *
476
476
  * console.log(error.toString())
477
- * // Output: "DatabaseError: Database connection failed. [DB_CONN_FAILED] (2024-01-15T10:30:45.123Z) metadata: {...}"
477
+ * // Output: "DatabaseError: Database connection failed. [DB_CONN_FAILED] 2025-01-15T10:30:45.123Z (1736937045123) metadata: {...}"
478
478
  * ```
479
479
  */
480
480
  toString(): string;
@@ -512,7 +512,7 @@ declare class ErrorX<TMetadata extends ErrorXMetadata = ErrorXMetadata> extends
512
512
  * code: 'DB_CONN_FAILED',
513
513
  * uiMessage: 'Database is temporarily unavailable',
514
514
  * metadata: { host: 'localhost' },
515
- * timestamp: '2024-01-15T10:30:45.123Z'
515
+ * timestamp: 1705315845123
516
516
  * }
517
517
  *
518
518
  * const error = ErrorX.fromJSON(serializedError)
@@ -533,7 +533,7 @@ declare class ErrorX<TMetadata extends ErrorXMetadata = ErrorXMetadata> extends
533
533
  * ### 1. Use Preset Directly
534
534
  * Create an error with all preset values:
535
535
  * ```typescript
536
- * throw new ErrorX(http.notFound)
536
+ * throw new ErrorX(http[404])
537
537
  * // Result: 404 error with message "Not found.", code, name, uiMessage, and type
538
538
  * ```
539
539
  *
@@ -541,7 +541,7 @@ declare class ErrorX<TMetadata extends ErrorXMetadata = ErrorXMetadata> extends
541
541
  * Customize the error while keeping other preset values:
542
542
  * ```typescript
543
543
  * throw new ErrorX({
544
- * ...http.notFound,
544
+ * ...http[404],
545
545
  * message: 'User not found',
546
546
  * metadata: { userId: 123 }
547
547
  * })
@@ -552,7 +552,7 @@ declare class ErrorX<TMetadata extends ErrorXMetadata = ErrorXMetadata> extends
552
552
  * Enhance presets with additional context:
553
553
  * ```typescript
554
554
  * throw new ErrorX({
555
- * ...http.unauthorized,
555
+ * ...http[401],
556
556
  * metadata: { attemptedAction: 'viewProfile', userId: 456 }
557
557
  * })
558
558
  * ```
@@ -564,7 +564,7 @@ declare class ErrorX<TMetadata extends ErrorXMetadata = ErrorXMetadata> extends
564
564
  * // some operation
565
565
  * } catch (originalError) {
566
566
  * throw new ErrorX({
567
- * ...http.internalServerError,
567
+ * ...http[500],
568
568
  * cause: originalError,
569
569
  * metadata: { operation: 'database-query' }
570
570
  * })
@@ -574,21 +574,21 @@ declare class ErrorX<TMetadata extends ErrorXMetadata = ErrorXMetadata> extends
574
574
  * ## Common HTTP Presets
575
575
  *
576
576
  * ### 4xx Client Errors
577
- * - `badRequest` (400) - Invalid request data
578
- * - `unauthorized` (401) - Authentication required
579
- * - `forbidden` (403) - Insufficient permissions
580
- * - `notFound` (404) - Resource not found
581
- * - `methodNotAllowed` (405) - HTTP method not allowed
582
- * - `conflict` (409) - Resource conflict
583
- * - `unprocessableEntity` (422) - Validation failed
584
- * - `tooManyRequests` (429) - Rate limit exceeded
577
+ * - `400` - Bad Request - Invalid request data
578
+ * - `401` - Unauthorized - Authentication required
579
+ * - `403` - Forbidden - Insufficient permissions
580
+ * - `404` - Not Found - Resource not found
581
+ * - `405` - Method Not Allowed - HTTP method not allowed
582
+ * - `409` - Conflict - Resource conflict
583
+ * - `422` - Unprocessable Entity - Validation failed
584
+ * - `429` - Too Many Requests - Rate limit exceeded
585
585
  *
586
586
  * ### 5xx Server Errors
587
- * - `internalServerError` (500) - Unexpected server error
588
- * - `notImplemented` (501) - Feature not implemented
589
- * - `badGateway` (502) - Upstream server error
590
- * - `serviceUnavailable` (503) - Service temporarily down
591
- * - `gatewayTimeout` (504) - Upstream timeout
587
+ * - `500` - Internal Server Error - Unexpected server error
588
+ * - `501` - Not Implemented - Feature not implemented
589
+ * - `502` - Bad Gateway - Upstream server error
590
+ * - `503` - Service Unavailable - Service temporarily down
591
+ * - `504` - Gateway Timeout - Upstream timeout
592
592
  *
593
593
  * @example
594
594
  * ```typescript
@@ -598,7 +598,7 @@ declare class ErrorX<TMetadata extends ErrorXMetadata = ErrorXMetadata> extends
598
598
  *
599
599
  * if (!user) {
600
600
  * throw new ErrorX({
601
- * ...http.notFound,
601
+ * ...http[404],
602
602
  * message: 'User not found',
603
603
  * metadata: { userId: req.params.id }
604
604
  * })
@@ -610,7 +610,7 @@ declare class ErrorX<TMetadata extends ErrorXMetadata = ErrorXMetadata> extends
610
610
  * // Authentication middleware example
611
611
  * const requireAuth = (req, res, next) => {
612
612
  * if (!req.user) {
613
- * throw new ErrorX(http.unauthorized)
613
+ * throw new ErrorX(http[401])
614
614
  * }
615
615
  * next()
616
616
  * }
@@ -618,7 +618,7 @@ declare class ErrorX<TMetadata extends ErrorXMetadata = ErrorXMetadata> extends
618
618
  * // Rate limiting example
619
619
  * if (isRateLimited(req.ip)) {
620
620
  * throw new ErrorX({
621
- * ...http.tooManyRequests,
621
+ * ...http[429],
622
622
  * metadata: {
623
623
  * ip: req.ip,
624
624
  * retryAfter: 60
@@ -630,7 +630,7 @@ declare class ErrorX<TMetadata extends ErrorXMetadata = ErrorXMetadata> extends
630
630
  * @public
631
631
  */
632
632
  declare const http: {
633
- readonly badRequest: {
633
+ readonly 400: {
634
634
  httpStatus: number;
635
635
  code: string;
636
636
  name: string;
@@ -638,7 +638,7 @@ declare const http: {
638
638
  uiMessage: string;
639
639
  type: string;
640
640
  };
641
- readonly unauthorized: {
641
+ readonly 401: {
642
642
  httpStatus: number;
643
643
  code: string;
644
644
  name: string;
@@ -646,7 +646,7 @@ declare const http: {
646
646
  uiMessage: string;
647
647
  type: string;
648
648
  };
649
- readonly paymentRequired: {
649
+ readonly 402: {
650
650
  httpStatus: number;
651
651
  code: string;
652
652
  name: string;
@@ -654,7 +654,7 @@ declare const http: {
654
654
  uiMessage: string;
655
655
  type: string;
656
656
  };
657
- readonly forbidden: {
657
+ readonly 403: {
658
658
  httpStatus: number;
659
659
  code: string;
660
660
  name: string;
@@ -662,7 +662,7 @@ declare const http: {
662
662
  uiMessage: string;
663
663
  type: string;
664
664
  };
665
- readonly notFound: {
665
+ readonly 404: {
666
666
  httpStatus: number;
667
667
  code: string;
668
668
  name: string;
@@ -670,7 +670,7 @@ declare const http: {
670
670
  uiMessage: string;
671
671
  type: string;
672
672
  };
673
- readonly methodNotAllowed: {
673
+ readonly 405: {
674
674
  httpStatus: number;
675
675
  code: string;
676
676
  name: string;
@@ -678,7 +678,7 @@ declare const http: {
678
678
  uiMessage: string;
679
679
  type: string;
680
680
  };
681
- readonly notAcceptable: {
681
+ readonly 406: {
682
682
  httpStatus: number;
683
683
  code: string;
684
684
  name: string;
@@ -686,7 +686,7 @@ declare const http: {
686
686
  uiMessage: string;
687
687
  type: string;
688
688
  };
689
- readonly proxyAuthenticationRequired: {
689
+ readonly 407: {
690
690
  httpStatus: number;
691
691
  code: string;
692
692
  name: string;
@@ -694,7 +694,7 @@ declare const http: {
694
694
  uiMessage: string;
695
695
  type: string;
696
696
  };
697
- readonly requestTimeout: {
697
+ readonly 408: {
698
698
  httpStatus: number;
699
699
  code: string;
700
700
  name: string;
@@ -702,7 +702,7 @@ declare const http: {
702
702
  uiMessage: string;
703
703
  type: string;
704
704
  };
705
- readonly conflict: {
705
+ readonly 409: {
706
706
  httpStatus: number;
707
707
  code: string;
708
708
  name: string;
@@ -710,7 +710,7 @@ declare const http: {
710
710
  uiMessage: string;
711
711
  type: string;
712
712
  };
713
- readonly gone: {
713
+ readonly 410: {
714
714
  httpStatus: number;
715
715
  code: string;
716
716
  name: string;
@@ -718,7 +718,7 @@ declare const http: {
718
718
  uiMessage: string;
719
719
  type: string;
720
720
  };
721
- readonly lengthRequired: {
721
+ readonly 411: {
722
722
  httpStatus: number;
723
723
  code: string;
724
724
  name: string;
@@ -726,7 +726,7 @@ declare const http: {
726
726
  uiMessage: string;
727
727
  type: string;
728
728
  };
729
- readonly preconditionFailed: {
729
+ readonly 412: {
730
730
  httpStatus: number;
731
731
  code: string;
732
732
  name: string;
@@ -734,7 +734,7 @@ declare const http: {
734
734
  uiMessage: string;
735
735
  type: string;
736
736
  };
737
- readonly payloadTooLarge: {
737
+ readonly 413: {
738
738
  httpStatus: number;
739
739
  code: string;
740
740
  name: string;
@@ -742,7 +742,7 @@ declare const http: {
742
742
  uiMessage: string;
743
743
  type: string;
744
744
  };
745
- readonly uriTooLong: {
745
+ readonly 414: {
746
746
  httpStatus: number;
747
747
  code: string;
748
748
  name: string;
@@ -750,7 +750,7 @@ declare const http: {
750
750
  uiMessage: string;
751
751
  type: string;
752
752
  };
753
- readonly unsupportedMediaType: {
753
+ readonly 415: {
754
754
  httpStatus: number;
755
755
  code: string;
756
756
  name: string;
@@ -758,7 +758,7 @@ declare const http: {
758
758
  uiMessage: string;
759
759
  type: string;
760
760
  };
761
- readonly rangeNotSatisfiable: {
761
+ readonly 416: {
762
762
  httpStatus: number;
763
763
  code: string;
764
764
  name: string;
@@ -766,7 +766,7 @@ declare const http: {
766
766
  uiMessage: string;
767
767
  type: string;
768
768
  };
769
- readonly expectationFailed: {
769
+ readonly 417: {
770
770
  httpStatus: number;
771
771
  code: string;
772
772
  name: string;
@@ -774,7 +774,7 @@ declare const http: {
774
774
  uiMessage: string;
775
775
  type: string;
776
776
  };
777
- readonly imATeapot: {
777
+ readonly 418: {
778
778
  httpStatus: number;
779
779
  code: string;
780
780
  name: string;
@@ -782,7 +782,7 @@ declare const http: {
782
782
  uiMessage: string;
783
783
  type: string;
784
784
  };
785
- readonly unprocessableEntity: {
785
+ readonly 422: {
786
786
  httpStatus: number;
787
787
  code: string;
788
788
  name: string;
@@ -790,7 +790,7 @@ declare const http: {
790
790
  uiMessage: string;
791
791
  type: string;
792
792
  };
793
- readonly locked: {
793
+ readonly 423: {
794
794
  httpStatus: number;
795
795
  code: string;
796
796
  name: string;
@@ -798,7 +798,7 @@ declare const http: {
798
798
  uiMessage: string;
799
799
  type: string;
800
800
  };
801
- readonly failedDependency: {
801
+ readonly 424: {
802
802
  httpStatus: number;
803
803
  code: string;
804
804
  name: string;
@@ -806,7 +806,7 @@ declare const http: {
806
806
  uiMessage: string;
807
807
  type: string;
808
808
  };
809
- readonly tooEarly: {
809
+ readonly 425: {
810
810
  httpStatus: number;
811
811
  code: string;
812
812
  name: string;
@@ -814,7 +814,7 @@ declare const http: {
814
814
  uiMessage: string;
815
815
  type: string;
816
816
  };
817
- readonly upgradeRequired: {
817
+ readonly 426: {
818
818
  httpStatus: number;
819
819
  code: string;
820
820
  name: string;
@@ -822,7 +822,7 @@ declare const http: {
822
822
  uiMessage: string;
823
823
  type: string;
824
824
  };
825
- readonly preconditionRequired: {
825
+ readonly 428: {
826
826
  httpStatus: number;
827
827
  code: string;
828
828
  name: string;
@@ -830,7 +830,7 @@ declare const http: {
830
830
  uiMessage: string;
831
831
  type: string;
832
832
  };
833
- readonly tooManyRequests: {
833
+ readonly 429: {
834
834
  httpStatus: number;
835
835
  code: string;
836
836
  name: string;
@@ -838,7 +838,7 @@ declare const http: {
838
838
  uiMessage: string;
839
839
  type: string;
840
840
  };
841
- readonly requestHeaderFieldsTooLarge: {
841
+ readonly 431: {
842
842
  httpStatus: number;
843
843
  code: string;
844
844
  name: string;
@@ -846,7 +846,7 @@ declare const http: {
846
846
  uiMessage: string;
847
847
  type: string;
848
848
  };
849
- readonly unavailableForLegalReasons: {
849
+ readonly 451: {
850
850
  httpStatus: number;
851
851
  code: string;
852
852
  name: string;
@@ -854,7 +854,7 @@ declare const http: {
854
854
  uiMessage: string;
855
855
  type: string;
856
856
  };
857
- readonly internalServerError: {
857
+ readonly 500: {
858
858
  httpStatus: number;
859
859
  code: string;
860
860
  name: string;
@@ -862,7 +862,7 @@ declare const http: {
862
862
  uiMessage: string;
863
863
  type: string;
864
864
  };
865
- readonly notImplemented: {
865
+ readonly 501: {
866
866
  httpStatus: number;
867
867
  code: string;
868
868
  name: string;
@@ -870,7 +870,7 @@ declare const http: {
870
870
  uiMessage: string;
871
871
  type: string;
872
872
  };
873
- readonly badGateway: {
873
+ readonly 502: {
874
874
  httpStatus: number;
875
875
  code: string;
876
876
  name: string;
@@ -878,7 +878,7 @@ declare const http: {
878
878
  uiMessage: string;
879
879
  type: string;
880
880
  };
881
- readonly serviceUnavailable: {
881
+ readonly 503: {
882
882
  httpStatus: number;
883
883
  code: string;
884
884
  name: string;
@@ -886,7 +886,7 @@ declare const http: {
886
886
  uiMessage: string;
887
887
  type: string;
888
888
  };
889
- readonly gatewayTimeout: {
889
+ readonly 504: {
890
890
  httpStatus: number;
891
891
  code: string;
892
892
  name: string;
@@ -894,7 +894,7 @@ declare const http: {
894
894
  uiMessage: string;
895
895
  type: string;
896
896
  };
897
- readonly httpVersionNotSupported: {
897
+ readonly 505: {
898
898
  httpStatus: number;
899
899
  code: string;
900
900
  name: string;
@@ -902,7 +902,7 @@ declare const http: {
902
902
  uiMessage: string;
903
903
  type: string;
904
904
  };
905
- readonly variantAlsoNegotiates: {
905
+ readonly 506: {
906
906
  httpStatus: number;
907
907
  code: string;
908
908
  name: string;
@@ -910,7 +910,7 @@ declare const http: {
910
910
  uiMessage: string;
911
911
  type: string;
912
912
  };
913
- readonly insufficientStorage: {
913
+ readonly 507: {
914
914
  httpStatus: number;
915
915
  code: string;
916
916
  name: string;
@@ -918,7 +918,7 @@ declare const http: {
918
918
  uiMessage: string;
919
919
  type: string;
920
920
  };
921
- readonly loopDetected: {
921
+ readonly 508: {
922
922
  httpStatus: number;
923
923
  code: string;
924
924
  name: string;
@@ -926,7 +926,7 @@ declare const http: {
926
926
  uiMessage: string;
927
927
  type: string;
928
928
  };
929
- readonly notExtended: {
929
+ readonly 510: {
930
930
  httpStatus: number;
931
931
  code: string;
932
932
  name: string;
@@ -934,7 +934,7 @@ declare const http: {
934
934
  uiMessage: string;
935
935
  type: string;
936
936
  };
937
- readonly networkAuthenticationRequired: {
937
+ readonly 511: {
938
938
  httpStatus: number;
939
939
  code: string;
940
940
  name: string;