@bombillazo/error-x 0.4.1 → 0.4.3

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
@@ -164,6 +164,11 @@ interface ErrorXConfig {
164
164
  * - string[]: Custom patterns to match and remove from stack traces
165
165
  */
166
166
  cleanStack?: boolean | string[];
167
+ /**
168
+ * Delimiter to trim stack traces after a specified line
169
+ * When set, stack traces will be trimmed to start after the first line containing this string
170
+ */
171
+ cleanStackDelimiter?: string;
167
172
  }
168
173
  /**
169
174
  * Enhanced Error class with rich metadata, type-safe error handling, and intelligent error conversion.
@@ -177,7 +182,8 @@ interface ErrorXConfig {
177
182
  * docsMap: {
178
183
  * 'AUTH_FAILED': 'errors/authentication',
179
184
  * 'DB_ERROR': 'errors/database'
180
- * }
185
+ * },
186
+ * cleanStackDelimiter: 'my-app-entry' // Clean stack traces after this line
181
187
  * })
182
188
  *
183
189
  * // Basic usage
@@ -286,7 +292,8 @@ declare class ErrorX<TMetadata extends ErrorXMetadata = ErrorXMetadata> extends
286
292
  * docsMap: {
287
293
  * 'AUTH_FAILED': 'authentication-errors',
288
294
  * 'DB_ERROR': 'database-errors'
289
- * }
295
+ * },
296
+ * cleanStackDelimiter: 'app-entry-point' // Trim stack traces after this line
290
297
  * })
291
298
  * ```
292
299
  */
@@ -296,6 +303,17 @@ declare class ErrorX<TMetadata extends ErrorXMetadata = ErrorXMetadata> extends
296
303
  * Returns null if no configuration has been set.
297
304
  */
298
305
  static getConfig(): ErrorXConfig | null;
306
+ /**
307
+ * Reset global configuration to null.
308
+ * Useful for testing or when you want to clear all configuration.
309
+ *
310
+ * @example
311
+ * ```typescript
312
+ * ErrorX.resetConfig()
313
+ * const config = ErrorX.getConfig() // null
314
+ * ```
315
+ */
316
+ static resetConfig(): void;
299
317
  /**
300
318
  * Validates HTTP status code to ensure it's within valid range (100-599)
301
319
  *
@@ -343,28 +361,24 @@ declare class ErrorX<TMetadata extends ErrorXMetadata = ErrorXMetadata> extends
343
361
  */
344
362
  private static preserveOriginalStackFromCause;
345
363
  /**
346
- * Cleans the stack trace by removing ErrorX internal method calls.
364
+ * Cleans a stack trace by removing ErrorX internal method calls and optionally trimming after a delimiter.
347
365
  * This provides cleaner stack traces that focus on user code.
348
366
  *
349
- * @param stack - Raw stack trace to clean
350
- * @returns Cleaned stack trace without ErrorX internal calls
351
- */
352
- private static cleanStack;
353
- /**
354
- * Processes an error's stack trace to trim it after a specified delimiter.
355
- * Useful for removing irrelevant stack frames before a specific function.
356
- *
357
- * @param error - Error whose stack to process
358
- * @param delimiter - String to search for in stack lines
359
- * @returns Processed stack trace starting after the delimiter
367
+ * @param stack - Raw stack trace string to clean
368
+ * @param delimiter - Optional delimiter to trim stack trace after (overrides config delimiter)
369
+ * @returns Cleaned stack trace without internal calls and optionally trimmed after delimiter
360
370
  *
361
371
  * @example
362
372
  * ```typescript
363
- * const processed = ErrorX.processErrorStack(error, 'my-app-entry')
373
+ * // Clean with pattern-based removal only
374
+ * const cleaned = ErrorX.cleanStack(error.stack)
375
+ *
376
+ * // Clean and trim after delimiter
377
+ * const trimmed = ErrorX.cleanStack(error.stack, 'my-app-entry')
364
378
  * // Returns stack trace starting after the line containing 'my-app-entry'
365
379
  * ```
366
380
  */
367
- private static processErrorStack;
381
+ static cleanStack(stack?: string, delimiter?: string): string;
368
382
  /**
369
383
  * Creates a new ErrorX instance with additional metadata merged with existing metadata.
370
384
  * The original error properties are preserved while extending the metadata.
@@ -444,21 +458,6 @@ declare class ErrorX<TMetadata extends ErrorXMetadata = ErrorXMetadata> extends
444
458
  static from(error: Error): ErrorX;
445
459
  static from(error: string): ErrorX;
446
460
  static from(error: unknown): ErrorX;
447
- /**
448
- * Creates a new ErrorX instance with cleaned stack trace using the specified delimiter.
449
- * Returns the same instance if no delimiter is provided or no stack is available.
450
- *
451
- * @param delimiter - Optional string to search for in stack lines
452
- * @returns New ErrorX instance with cleaned stack trace, or the same instance if no cleaning needed
453
- *
454
- * @example
455
- * ```typescript
456
- * const error = new ErrorX({ message: 'Database error' })
457
- * const cleanedError = error.cleanStackTrace('database-layer')
458
- * // Returns new ErrorX with stack trace starting after 'database-layer'
459
- * ```
460
- */
461
- cleanStackTrace(delimiter?: string): ErrorX<TMetadata>;
462
461
  /**
463
462
  * Converts the ErrorX instance to a detailed string representation.
464
463
  * Includes error name, message, code, timestamp, metadata, and stack trace.
@@ -534,7 +533,7 @@ declare class ErrorX<TMetadata extends ErrorXMetadata = ErrorXMetadata> extends
534
533
  * ### 1. Use Preset Directly
535
534
  * Create an error with all preset values:
536
535
  * ```typescript
537
- * throw new ErrorX(http.notFound)
536
+ * throw new ErrorX(http[404])
538
537
  * // Result: 404 error with message "Not found.", code, name, uiMessage, and type
539
538
  * ```
540
539
  *
@@ -542,7 +541,7 @@ declare class ErrorX<TMetadata extends ErrorXMetadata = ErrorXMetadata> extends
542
541
  * Customize the error while keeping other preset values:
543
542
  * ```typescript
544
543
  * throw new ErrorX({
545
- * ...http.notFound,
544
+ * ...http[404],
546
545
  * message: 'User not found',
547
546
  * metadata: { userId: 123 }
548
547
  * })
@@ -553,7 +552,7 @@ declare class ErrorX<TMetadata extends ErrorXMetadata = ErrorXMetadata> extends
553
552
  * Enhance presets with additional context:
554
553
  * ```typescript
555
554
  * throw new ErrorX({
556
- * ...http.unauthorized,
555
+ * ...http[401],
557
556
  * metadata: { attemptedAction: 'viewProfile', userId: 456 }
558
557
  * })
559
558
  * ```
@@ -565,7 +564,7 @@ declare class ErrorX<TMetadata extends ErrorXMetadata = ErrorXMetadata> extends
565
564
  * // some operation
566
565
  * } catch (originalError) {
567
566
  * throw new ErrorX({
568
- * ...http.internalServerError,
567
+ * ...http[500],
569
568
  * cause: originalError,
570
569
  * metadata: { operation: 'database-query' }
571
570
  * })
@@ -575,21 +574,21 @@ declare class ErrorX<TMetadata extends ErrorXMetadata = ErrorXMetadata> extends
575
574
  * ## Common HTTP Presets
576
575
  *
577
576
  * ### 4xx Client Errors
578
- * - `badRequest` (400) - Invalid request data
579
- * - `unauthorized` (401) - Authentication required
580
- * - `forbidden` (403) - Insufficient permissions
581
- * - `notFound` (404) - Resource not found
582
- * - `methodNotAllowed` (405) - HTTP method not allowed
583
- * - `conflict` (409) - Resource conflict
584
- * - `unprocessableEntity` (422) - Validation failed
585
- * - `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
586
585
  *
587
586
  * ### 5xx Server Errors
588
- * - `internalServerError` (500) - Unexpected server error
589
- * - `notImplemented` (501) - Feature not implemented
590
- * - `badGateway` (502) - Upstream server error
591
- * - `serviceUnavailable` (503) - Service temporarily down
592
- * - `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
593
592
  *
594
593
  * @example
595
594
  * ```typescript
@@ -599,7 +598,7 @@ declare class ErrorX<TMetadata extends ErrorXMetadata = ErrorXMetadata> extends
599
598
  *
600
599
  * if (!user) {
601
600
  * throw new ErrorX({
602
- * ...http.notFound,
601
+ * ...http[404],
603
602
  * message: 'User not found',
604
603
  * metadata: { userId: req.params.id }
605
604
  * })
@@ -611,7 +610,7 @@ declare class ErrorX<TMetadata extends ErrorXMetadata = ErrorXMetadata> extends
611
610
  * // Authentication middleware example
612
611
  * const requireAuth = (req, res, next) => {
613
612
  * if (!req.user) {
614
- * throw new ErrorX(http.unauthorized)
613
+ * throw new ErrorX(http[401])
615
614
  * }
616
615
  * next()
617
616
  * }
@@ -619,7 +618,7 @@ declare class ErrorX<TMetadata extends ErrorXMetadata = ErrorXMetadata> extends
619
618
  * // Rate limiting example
620
619
  * if (isRateLimited(req.ip)) {
621
620
  * throw new ErrorX({
622
- * ...http.tooManyRequests,
621
+ * ...http[429],
623
622
  * metadata: {
624
623
  * ip: req.ip,
625
624
  * retryAfter: 60
@@ -631,7 +630,7 @@ declare class ErrorX<TMetadata extends ErrorXMetadata = ErrorXMetadata> extends
631
630
  * @public
632
631
  */
633
632
  declare const http: {
634
- readonly badRequest: {
633
+ readonly 400: {
635
634
  httpStatus: number;
636
635
  code: string;
637
636
  name: string;
@@ -639,7 +638,7 @@ declare const http: {
639
638
  uiMessage: string;
640
639
  type: string;
641
640
  };
642
- readonly unauthorized: {
641
+ readonly 401: {
643
642
  httpStatus: number;
644
643
  code: string;
645
644
  name: string;
@@ -647,7 +646,7 @@ declare const http: {
647
646
  uiMessage: string;
648
647
  type: string;
649
648
  };
650
- readonly paymentRequired: {
649
+ readonly 402: {
651
650
  httpStatus: number;
652
651
  code: string;
653
652
  name: string;
@@ -655,7 +654,7 @@ declare const http: {
655
654
  uiMessage: string;
656
655
  type: string;
657
656
  };
658
- readonly forbidden: {
657
+ readonly 403: {
659
658
  httpStatus: number;
660
659
  code: string;
661
660
  name: string;
@@ -663,7 +662,7 @@ declare const http: {
663
662
  uiMessage: string;
664
663
  type: string;
665
664
  };
666
- readonly notFound: {
665
+ readonly 404: {
667
666
  httpStatus: number;
668
667
  code: string;
669
668
  name: string;
@@ -671,7 +670,7 @@ declare const http: {
671
670
  uiMessage: string;
672
671
  type: string;
673
672
  };
674
- readonly methodNotAllowed: {
673
+ readonly 405: {
675
674
  httpStatus: number;
676
675
  code: string;
677
676
  name: string;
@@ -679,7 +678,7 @@ declare const http: {
679
678
  uiMessage: string;
680
679
  type: string;
681
680
  };
682
- readonly notAcceptable: {
681
+ readonly 406: {
683
682
  httpStatus: number;
684
683
  code: string;
685
684
  name: string;
@@ -687,7 +686,7 @@ declare const http: {
687
686
  uiMessage: string;
688
687
  type: string;
689
688
  };
690
- readonly proxyAuthenticationRequired: {
689
+ readonly 407: {
691
690
  httpStatus: number;
692
691
  code: string;
693
692
  name: string;
@@ -695,7 +694,7 @@ declare const http: {
695
694
  uiMessage: string;
696
695
  type: string;
697
696
  };
698
- readonly requestTimeout: {
697
+ readonly 408: {
699
698
  httpStatus: number;
700
699
  code: string;
701
700
  name: string;
@@ -703,7 +702,7 @@ declare const http: {
703
702
  uiMessage: string;
704
703
  type: string;
705
704
  };
706
- readonly conflict: {
705
+ readonly 409: {
707
706
  httpStatus: number;
708
707
  code: string;
709
708
  name: string;
@@ -711,7 +710,7 @@ declare const http: {
711
710
  uiMessage: string;
712
711
  type: string;
713
712
  };
714
- readonly gone: {
713
+ readonly 410: {
715
714
  httpStatus: number;
716
715
  code: string;
717
716
  name: string;
@@ -719,7 +718,7 @@ declare const http: {
719
718
  uiMessage: string;
720
719
  type: string;
721
720
  };
722
- readonly lengthRequired: {
721
+ readonly 411: {
723
722
  httpStatus: number;
724
723
  code: string;
725
724
  name: string;
@@ -727,7 +726,7 @@ declare const http: {
727
726
  uiMessage: string;
728
727
  type: string;
729
728
  };
730
- readonly preconditionFailed: {
729
+ readonly 412: {
731
730
  httpStatus: number;
732
731
  code: string;
733
732
  name: string;
@@ -735,7 +734,7 @@ declare const http: {
735
734
  uiMessage: string;
736
735
  type: string;
737
736
  };
738
- readonly payloadTooLarge: {
737
+ readonly 413: {
739
738
  httpStatus: number;
740
739
  code: string;
741
740
  name: string;
@@ -743,7 +742,7 @@ declare const http: {
743
742
  uiMessage: string;
744
743
  type: string;
745
744
  };
746
- readonly uriTooLong: {
745
+ readonly 414: {
747
746
  httpStatus: number;
748
747
  code: string;
749
748
  name: string;
@@ -751,7 +750,7 @@ declare const http: {
751
750
  uiMessage: string;
752
751
  type: string;
753
752
  };
754
- readonly unsupportedMediaType: {
753
+ readonly 415: {
755
754
  httpStatus: number;
756
755
  code: string;
757
756
  name: string;
@@ -759,7 +758,7 @@ declare const http: {
759
758
  uiMessage: string;
760
759
  type: string;
761
760
  };
762
- readonly rangeNotSatisfiable: {
761
+ readonly 416: {
763
762
  httpStatus: number;
764
763
  code: string;
765
764
  name: string;
@@ -767,7 +766,7 @@ declare const http: {
767
766
  uiMessage: string;
768
767
  type: string;
769
768
  };
770
- readonly expectationFailed: {
769
+ readonly 417: {
771
770
  httpStatus: number;
772
771
  code: string;
773
772
  name: string;
@@ -775,7 +774,7 @@ declare const http: {
775
774
  uiMessage: string;
776
775
  type: string;
777
776
  };
778
- readonly imATeapot: {
777
+ readonly 418: {
779
778
  httpStatus: number;
780
779
  code: string;
781
780
  name: string;
@@ -783,7 +782,7 @@ declare const http: {
783
782
  uiMessage: string;
784
783
  type: string;
785
784
  };
786
- readonly unprocessableEntity: {
785
+ readonly 422: {
787
786
  httpStatus: number;
788
787
  code: string;
789
788
  name: string;
@@ -791,7 +790,7 @@ declare const http: {
791
790
  uiMessage: string;
792
791
  type: string;
793
792
  };
794
- readonly locked: {
793
+ readonly 423: {
795
794
  httpStatus: number;
796
795
  code: string;
797
796
  name: string;
@@ -799,7 +798,7 @@ declare const http: {
799
798
  uiMessage: string;
800
799
  type: string;
801
800
  };
802
- readonly failedDependency: {
801
+ readonly 424: {
803
802
  httpStatus: number;
804
803
  code: string;
805
804
  name: string;
@@ -807,7 +806,7 @@ declare const http: {
807
806
  uiMessage: string;
808
807
  type: string;
809
808
  };
810
- readonly tooEarly: {
809
+ readonly 425: {
811
810
  httpStatus: number;
812
811
  code: string;
813
812
  name: string;
@@ -815,7 +814,7 @@ declare const http: {
815
814
  uiMessage: string;
816
815
  type: string;
817
816
  };
818
- readonly upgradeRequired: {
817
+ readonly 426: {
819
818
  httpStatus: number;
820
819
  code: string;
821
820
  name: string;
@@ -823,7 +822,7 @@ declare const http: {
823
822
  uiMessage: string;
824
823
  type: string;
825
824
  };
826
- readonly preconditionRequired: {
825
+ readonly 428: {
827
826
  httpStatus: number;
828
827
  code: string;
829
828
  name: string;
@@ -831,7 +830,7 @@ declare const http: {
831
830
  uiMessage: string;
832
831
  type: string;
833
832
  };
834
- readonly tooManyRequests: {
833
+ readonly 429: {
835
834
  httpStatus: number;
836
835
  code: string;
837
836
  name: string;
@@ -839,7 +838,7 @@ declare const http: {
839
838
  uiMessage: string;
840
839
  type: string;
841
840
  };
842
- readonly requestHeaderFieldsTooLarge: {
841
+ readonly 431: {
843
842
  httpStatus: number;
844
843
  code: string;
845
844
  name: string;
@@ -847,7 +846,7 @@ declare const http: {
847
846
  uiMessage: string;
848
847
  type: string;
849
848
  };
850
- readonly unavailableForLegalReasons: {
849
+ readonly 451: {
851
850
  httpStatus: number;
852
851
  code: string;
853
852
  name: string;
@@ -855,7 +854,7 @@ declare const http: {
855
854
  uiMessage: string;
856
855
  type: string;
857
856
  };
858
- readonly internalServerError: {
857
+ readonly 500: {
859
858
  httpStatus: number;
860
859
  code: string;
861
860
  name: string;
@@ -863,7 +862,7 @@ declare const http: {
863
862
  uiMessage: string;
864
863
  type: string;
865
864
  };
866
- readonly notImplemented: {
865
+ readonly 501: {
867
866
  httpStatus: number;
868
867
  code: string;
869
868
  name: string;
@@ -871,7 +870,7 @@ declare const http: {
871
870
  uiMessage: string;
872
871
  type: string;
873
872
  };
874
- readonly badGateway: {
873
+ readonly 502: {
875
874
  httpStatus: number;
876
875
  code: string;
877
876
  name: string;
@@ -879,7 +878,7 @@ declare const http: {
879
878
  uiMessage: string;
880
879
  type: string;
881
880
  };
882
- readonly serviceUnavailable: {
881
+ readonly 503: {
883
882
  httpStatus: number;
884
883
  code: string;
885
884
  name: string;
@@ -887,7 +886,7 @@ declare const http: {
887
886
  uiMessage: string;
888
887
  type: string;
889
888
  };
890
- readonly gatewayTimeout: {
889
+ readonly 504: {
891
890
  httpStatus: number;
892
891
  code: string;
893
892
  name: string;
@@ -895,7 +894,7 @@ declare const http: {
895
894
  uiMessage: string;
896
895
  type: string;
897
896
  };
898
- readonly httpVersionNotSupported: {
897
+ readonly 505: {
899
898
  httpStatus: number;
900
899
  code: string;
901
900
  name: string;
@@ -903,7 +902,7 @@ declare const http: {
903
902
  uiMessage: string;
904
903
  type: string;
905
904
  };
906
- readonly variantAlsoNegotiates: {
905
+ readonly 506: {
907
906
  httpStatus: number;
908
907
  code: string;
909
908
  name: string;
@@ -911,7 +910,7 @@ declare const http: {
911
910
  uiMessage: string;
912
911
  type: string;
913
912
  };
914
- readonly insufficientStorage: {
913
+ readonly 507: {
915
914
  httpStatus: number;
916
915
  code: string;
917
916
  name: string;
@@ -919,7 +918,7 @@ declare const http: {
919
918
  uiMessage: string;
920
919
  type: string;
921
920
  };
922
- readonly loopDetected: {
921
+ readonly 508: {
923
922
  httpStatus: number;
924
923
  code: string;
925
924
  name: string;
@@ -927,7 +926,7 @@ declare const http: {
927
926
  uiMessage: string;
928
927
  type: string;
929
928
  };
930
- readonly notExtended: {
929
+ readonly 510: {
931
930
  httpStatus: number;
932
931
  code: string;
933
932
  name: string;
@@ -935,7 +934,7 @@ declare const http: {
935
934
  uiMessage: string;
936
935
  type: string;
937
936
  };
938
- readonly networkAuthenticationRequired: {
937
+ readonly 511: {
939
938
  httpStatus: number;
940
939
  code: string;
941
940
  name: string;