error-shield 2.0.0 → 2.0.1
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/LICENSE +15 -0
- package/README.md +335 -141
- package/dist/cjs/index.cjs +270 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/esm/index.js +238 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/index.d.ts +4 -90
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/types/index.d.ts +182 -0
- package/package.json +63 -28
package/dist/index.d.ts
CHANGED
|
@@ -18,6 +18,8 @@ export interface ErrorHandlerOptions {
|
|
|
18
18
|
logger?: (error: ErrorDetails) => void;
|
|
19
19
|
context?: Record<string, any>;
|
|
20
20
|
}
|
|
21
|
+
export type ErrorFn = (message: string, context?: Record<string, any>) => AppError;
|
|
22
|
+
export type ErrorMap = Record<string, ErrorFn>;
|
|
21
23
|
/**
|
|
22
24
|
* Custom Error class with additional properties
|
|
23
25
|
*/
|
|
@@ -51,51 +53,7 @@ export declare function createErrorResponse(message: string, statusCode?: number
|
|
|
51
53
|
/**
|
|
52
54
|
* Common error creators
|
|
53
55
|
*/
|
|
54
|
-
export declare const
|
|
55
|
-
badRequest: (message: string, context?: Record<string, any>) => AppError;
|
|
56
|
-
unauthorized: (message?: string, context?: Record<string, any>) => AppError;
|
|
57
|
-
paymentRequired: (message?: string, context?: Record<string, any>) => AppError;
|
|
58
|
-
forbidden: (message?: string, context?: Record<string, any>) => AppError;
|
|
59
|
-
notFound: (message?: string, context?: Record<string, any>) => AppError;
|
|
60
|
-
methodNotAllowed: (message?: string, context?: Record<string, any>) => AppError;
|
|
61
|
-
notAcceptable: (message?: string, context?: Record<string, any>) => AppError;
|
|
62
|
-
proxyAuthRequired: (message?: string, context?: Record<string, any>) => AppError;
|
|
63
|
-
requestTimeout: (message?: string, context?: Record<string, any>) => AppError;
|
|
64
|
-
conflict: (message: string, context?: Record<string, any>) => AppError;
|
|
65
|
-
gone: (message?: string, context?: Record<string, any>) => AppError;
|
|
66
|
-
lengthRequired: (message?: string, context?: Record<string, any>) => AppError;
|
|
67
|
-
preconditionFailed: (message?: string, context?: Record<string, any>) => AppError;
|
|
68
|
-
payloadTooLarge: (message?: string, context?: Record<string, any>) => AppError;
|
|
69
|
-
uriTooLong: (message?: string, context?: Record<string, any>) => AppError;
|
|
70
|
-
unsupportedMediaType: (message?: string, context?: Record<string, any>) => AppError;
|
|
71
|
-
rangeNotSatisfiable: (message?: string, context?: Record<string, any>) => AppError;
|
|
72
|
-
expectationFailed: (message?: string, context?: Record<string, any>) => AppError;
|
|
73
|
-
imATeapot: (message?: string, context?: Record<string, any>) => AppError;
|
|
74
|
-
misdirectedRequest: (message?: string, context?: Record<string, any>) => AppError;
|
|
75
|
-
unprocessableEntity: (message?: string, context?: Record<string, any>) => AppError;
|
|
76
|
-
validationError: (message: string, context?: Record<string, any>) => AppError;
|
|
77
|
-
locked: (message?: string, context?: Record<string, any>) => AppError;
|
|
78
|
-
failedDependency: (message?: string, context?: Record<string, any>) => AppError;
|
|
79
|
-
tooEarly: (message?: string, context?: Record<string, any>) => AppError;
|
|
80
|
-
upgradeRequired: (message?: string, context?: Record<string, any>) => AppError;
|
|
81
|
-
preconditionRequired: (message?: string, context?: Record<string, any>) => AppError;
|
|
82
|
-
tooManyRequests: (message?: string, context?: Record<string, any>) => AppError;
|
|
83
|
-
requestHeaderFieldsTooLarge: (message?: string, context?: Record<string, any>) => AppError;
|
|
84
|
-
unavailableForLegalReasons: (message?: string, context?: Record<string, any>) => AppError;
|
|
85
|
-
internalServerError: (message?: string, context?: Record<string, any>) => AppError;
|
|
86
|
-
notImplemented: (message?: string, context?: Record<string, any>) => AppError;
|
|
87
|
-
badGateway: (message?: string, context?: Record<string, any>) => AppError;
|
|
88
|
-
serviceUnavailable: (message?: string, context?: Record<string, any>) => AppError;
|
|
89
|
-
gatewayTimeout: (message?: string, context?: Record<string, any>) => AppError;
|
|
90
|
-
httpVersionNotSupported: (message?: string, context?: Record<string, any>) => AppError;
|
|
91
|
-
variantAlsoNegotiates: (message?: string, context?: Record<string, any>) => AppError;
|
|
92
|
-
insufficientStorage: (message?: string, context?: Record<string, any>) => AppError;
|
|
93
|
-
loopDetected: (message?: string, context?: Record<string, any>) => AppError;
|
|
94
|
-
bandwidthLimitExceeded: (message?: string, context?: Record<string, any>) => AppError;
|
|
95
|
-
notExtended: (message?: string, context?: Record<string, any>) => AppError;
|
|
96
|
-
networkAuthenticationRequired: (message?: string, context?: Record<string, any>) => AppError;
|
|
97
|
-
networkConnectTimeout: (message?: string, context?: Record<string, any>) => AppError;
|
|
98
|
-
};
|
|
56
|
+
export declare const Errors: ErrorMap;
|
|
99
57
|
declare const _default: {
|
|
100
58
|
AppError: typeof AppError;
|
|
101
59
|
formatError: typeof formatError;
|
|
@@ -103,51 +61,7 @@ declare const _default: {
|
|
|
103
61
|
asyncHandler: typeof asyncHandler;
|
|
104
62
|
expressErrorHandler: typeof expressErrorHandler;
|
|
105
63
|
createErrorResponse: typeof createErrorResponse;
|
|
106
|
-
|
|
107
|
-
badRequest: (message: string, context?: Record<string, any>) => AppError;
|
|
108
|
-
unauthorized: (message?: string, context?: Record<string, any>) => AppError;
|
|
109
|
-
paymentRequired: (message?: string, context?: Record<string, any>) => AppError;
|
|
110
|
-
forbidden: (message?: string, context?: Record<string, any>) => AppError;
|
|
111
|
-
notFound: (message?: string, context?: Record<string, any>) => AppError;
|
|
112
|
-
methodNotAllowed: (message?: string, context?: Record<string, any>) => AppError;
|
|
113
|
-
notAcceptable: (message?: string, context?: Record<string, any>) => AppError;
|
|
114
|
-
proxyAuthRequired: (message?: string, context?: Record<string, any>) => AppError;
|
|
115
|
-
requestTimeout: (message?: string, context?: Record<string, any>) => AppError;
|
|
116
|
-
conflict: (message: string, context?: Record<string, any>) => AppError;
|
|
117
|
-
gone: (message?: string, context?: Record<string, any>) => AppError;
|
|
118
|
-
lengthRequired: (message?: string, context?: Record<string, any>) => AppError;
|
|
119
|
-
preconditionFailed: (message?: string, context?: Record<string, any>) => AppError;
|
|
120
|
-
payloadTooLarge: (message?: string, context?: Record<string, any>) => AppError;
|
|
121
|
-
uriTooLong: (message?: string, context?: Record<string, any>) => AppError;
|
|
122
|
-
unsupportedMediaType: (message?: string, context?: Record<string, any>) => AppError;
|
|
123
|
-
rangeNotSatisfiable: (message?: string, context?: Record<string, any>) => AppError;
|
|
124
|
-
expectationFailed: (message?: string, context?: Record<string, any>) => AppError;
|
|
125
|
-
imATeapot: (message?: string, context?: Record<string, any>) => AppError;
|
|
126
|
-
misdirectedRequest: (message?: string, context?: Record<string, any>) => AppError;
|
|
127
|
-
unprocessableEntity: (message?: string, context?: Record<string, any>) => AppError;
|
|
128
|
-
validationError: (message: string, context?: Record<string, any>) => AppError;
|
|
129
|
-
locked: (message?: string, context?: Record<string, any>) => AppError;
|
|
130
|
-
failedDependency: (message?: string, context?: Record<string, any>) => AppError;
|
|
131
|
-
tooEarly: (message?: string, context?: Record<string, any>) => AppError;
|
|
132
|
-
upgradeRequired: (message?: string, context?: Record<string, any>) => AppError;
|
|
133
|
-
preconditionRequired: (message?: string, context?: Record<string, any>) => AppError;
|
|
134
|
-
tooManyRequests: (message?: string, context?: Record<string, any>) => AppError;
|
|
135
|
-
requestHeaderFieldsTooLarge: (message?: string, context?: Record<string, any>) => AppError;
|
|
136
|
-
unavailableForLegalReasons: (message?: string, context?: Record<string, any>) => AppError;
|
|
137
|
-
internalServerError: (message?: string, context?: Record<string, any>) => AppError;
|
|
138
|
-
notImplemented: (message?: string, context?: Record<string, any>) => AppError;
|
|
139
|
-
badGateway: (message?: string, context?: Record<string, any>) => AppError;
|
|
140
|
-
serviceUnavailable: (message?: string, context?: Record<string, any>) => AppError;
|
|
141
|
-
gatewayTimeout: (message?: string, context?: Record<string, any>) => AppError;
|
|
142
|
-
httpVersionNotSupported: (message?: string, context?: Record<string, any>) => AppError;
|
|
143
|
-
variantAlsoNegotiates: (message?: string, context?: Record<string, any>) => AppError;
|
|
144
|
-
insufficientStorage: (message?: string, context?: Record<string, any>) => AppError;
|
|
145
|
-
loopDetected: (message?: string, context?: Record<string, any>) => AppError;
|
|
146
|
-
bandwidthLimitExceeded: (message?: string, context?: Record<string, any>) => AppError;
|
|
147
|
-
notExtended: (message?: string, context?: Record<string, any>) => AppError;
|
|
148
|
-
networkAuthenticationRequired: (message?: string, context?: Record<string, any>) => AppError;
|
|
149
|
-
networkConnectTimeout: (message?: string, context?: Record<string, any>) => AppError;
|
|
150
|
-
};
|
|
64
|
+
Errors: ErrorMap;
|
|
151
65
|
};
|
|
152
66
|
export default _default;
|
|
153
67
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC/B;AAED,MAAM,WAAW,mBAAmB;IAClC,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC3B,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC;IACvC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC/B;AAED;;GAEG;AACH,qBAAa,QAAS,SAAQ,KAAK;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CA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,YAAY,CAQd;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,EACrE,EAAE,EAAE,CAAC,GACJ,CAAC,CAMH;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,GAAE,mBAAwB,IAG/B,KAAK,KAAK,GAAG,QAAQ,EACrB,KAAK,GAAG,EACR,KAAK,GAAG,EACR,MAAM,GAAG,KACR,IAAI,CAoBR;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,MAAM,EACf,UAAU,GAAE,MAAY,EACxB,IAAI,CAAC,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC5B,QAAQ,CAEV;AAED;;GAEG;AACH,eAAO,MAAM,MAAM,EAAE,QAmIpB,CAAC;;;;;;;;;;AAGF,wBAQE"}
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Provides utilities for error handling, formatting, and logging
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.
|
|
8
|
+
exports.Errors = exports.AppError = void 0;
|
|
9
9
|
exports.formatError = formatError;
|
|
10
10
|
exports.handleError = handleError;
|
|
11
11
|
exports.asyncHandler = asyncHandler;
|
|
@@ -100,7 +100,7 @@ function createErrorResponse(message, statusCode = 500, code, context) {
|
|
|
100
100
|
/**
|
|
101
101
|
* Common error creators
|
|
102
102
|
*/
|
|
103
|
-
exports.
|
|
103
|
+
exports.Errors = {
|
|
104
104
|
// 4xx Client Errors
|
|
105
105
|
badRequest: (message, context) => new AppError(message, 400, 'BAD_REQUEST', context),
|
|
106
106
|
unauthorized: (message = 'Unauthorized', context) => new AppError(message, 401, 'UNAUTHORIZED', context),
|
|
@@ -155,6 +155,6 @@ exports.default = {
|
|
|
155
155
|
asyncHandler,
|
|
156
156
|
expressErrorHandler,
|
|
157
157
|
createErrorResponse,
|
|
158
|
-
|
|
158
|
+
Errors: exports.Errors,
|
|
159
159
|
};
|
|
160
160
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAqDH,kCA0BC;AAKD,kCAWC;AAKD,oCAQC;AAKD,kDA4BC;AAKD,kDAOC;AAlID;;GAEG;AACH,MAAa,QAAS,SAAQ,KAAK;IAMjC,YACE,OAAe,EACf,aAAqB,GAAG,EACxB,IAAa,EACb,OAA6B;QAE7B,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;QAClC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;QAC1B,IAAK,KAAa,CAAC,iBAAiB,EAAE,CAAC;YACpC,KAAa,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QAC3D,CAAC;IACH,CAAC;CACF;AAtBD,4BAsBC;AAED;;GAEG;AACH,SAAgB,WAAW,CACzB,KAAuB,EACvB,UAA+B,EAAE;IAEjC,MAAM,EACJ,YAAY,GAAG,KAAK,EACpB,gBAAgB,GAAG,IAAI,EACvB,OAAO,EAAE,cAAc,GAAG,EAAE,GAC7B,GAAG,OAAO,CAAC;IAEZ,MAAM,aAAa,GAAG,KAAK,YAAY,QAAQ;QAC7C,CAAC,CAAC,EAAE,GAAG,KAAK,C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AE,GAAG,EAAE,yBAAyB,EAAE,OAAO,CAAC;IAEhE,mBAAmB,EAAE,CAAC,UAAkB,sBAAsB,EAAE,OAA6B,EAAE,EAAE,CAC/F,IAAI,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE,sBAAsB,EAAE,OAAO,CAAC;IAE7D,YAAY,EAAE,CAAC,UAAkB,eAAe,EAAE,OAA6B,EAAE,EAAE,CACjF,IAAI,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE,eAAe,EAAE,OAAO,CAAC;IAEtD,sBAAsB,EAAE,CAAC,UAAkB,0BAA0B,EAAE,OAA6B,EAAE,EAAE,CACtG,IAAI,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE,0BAA0B,EAAE,OAAO,CAAC;IAEjE,WAAW,EAAE,CAAC,UAAkB,cAAc,EAAE,OAA6B,EAAE,EAAE,CAC/E,IAAI,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE,cAAc,EAAE,OAAO,CAAC;IAErD,6BAA6B,EAAE,CAAC,UAAkB,iCAAiC,EAAE,OAA6B,EAAE,EAAE,CACpH,IAAI,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE,iCAAiC,EAAE,OAAO,CAAC;IAExE,qBAAqB,EAAE,CAAC,UAAkB,yBAAyB,EAAE,OAA6B,EAAE,EAAE,CACpG,IAAI,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE,yBAAyB,EAAE,OAAO,CAAC;CACjE,CAAC;AAEF,iBAAiB;AACjB,kBAAe;IACb,QAAQ;IACR,WAAW;IACX,WAAW;IACX,YAAY;IACZ,mBAAmB;IACnB,mBAAmB;IACnB,MAAM,EAAN,cAAM;CACP,CAAC"}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error Shield - A comprehensive error handling utility for Node.js & Express.js
|
|
3
|
+
*
|
|
4
|
+
* Provides utilities for error handling, formatting, logging, retry logic,
|
|
5
|
+
* and error chaining with full TypeScript support.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Structured representation of an error with optional metadata.
|
|
11
|
+
*/
|
|
12
|
+
interface ErrorDetails {
|
|
13
|
+
message: string;
|
|
14
|
+
code?: string;
|
|
15
|
+
statusCode?: number;
|
|
16
|
+
stack?: string;
|
|
17
|
+
timestamp?: string;
|
|
18
|
+
context?: Record<string, any>;
|
|
19
|
+
/** Cause chain information when error chaining is used */
|
|
20
|
+
cause?: ErrorDetails;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Options for configuring error handling behavior.
|
|
24
|
+
*/
|
|
25
|
+
interface ErrorHandlerOptions {
|
|
26
|
+
includeStack?: boolean;
|
|
27
|
+
includeTimestamp?: boolean;
|
|
28
|
+
format?: 'json' | 'string';
|
|
29
|
+
logger?: (error: ErrorDetails) => void;
|
|
30
|
+
context?: Record<string, any>;
|
|
31
|
+
}
|
|
32
|
+
type ErrorFn = (message: string, context?: Record<string, any>) => AppError;
|
|
33
|
+
type ErrorMap = Record<string, ErrorFn>;
|
|
34
|
+
/**
|
|
35
|
+
* Configuration options for the retry utility.
|
|
36
|
+
*/
|
|
37
|
+
interface RetryOptions {
|
|
38
|
+
/** Maximum number of retry attempts (default: 3) */
|
|
39
|
+
maxRetries?: number;
|
|
40
|
+
/** Backoff strategy between retries (default: 'exponential') */
|
|
41
|
+
backoff?: 'exponential' | 'linear' | 'fixed';
|
|
42
|
+
/** Initial delay in milliseconds before the first retry (default: 1000) */
|
|
43
|
+
initialDelay?: number;
|
|
44
|
+
/** Maximum delay in milliseconds between retries (default: 30000) */
|
|
45
|
+
maxDelay?: number;
|
|
46
|
+
/**
|
|
47
|
+
* Optional predicate to determine whether a retry should be attempted.
|
|
48
|
+
* If provided and returns `false`, the error is thrown immediately.
|
|
49
|
+
*/
|
|
50
|
+
retryIf?: (error: Error) => boolean;
|
|
51
|
+
/** Optional callback invoked before each retry attempt */
|
|
52
|
+
onRetry?: (error: Error, attempt: number) => void;
|
|
53
|
+
/** Whether to add random jitter to the delay to prevent thundering herd (default: true) */
|
|
54
|
+
jitter?: boolean;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Custom Error class with additional properties for structured error handling.
|
|
58
|
+
*
|
|
59
|
+
* Supports error chaining via the native ES2022 `Error.cause` feature.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* const error = new AppError('Something broke', 500, 'INTERNAL', { userId: 123 });
|
|
64
|
+
*
|
|
65
|
+
* // With error chaining
|
|
66
|
+
* try {
|
|
67
|
+
* await fetchData();
|
|
68
|
+
* } catch (err) {
|
|
69
|
+
* throw new AppError('Failed to fetch data', 502, 'FETCH_FAILED', undefined, err);
|
|
70
|
+
* }
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
declare class AppError extends Error {
|
|
74
|
+
code?: string;
|
|
75
|
+
statusCode?: number;
|
|
76
|
+
context?: Record<string, any>;
|
|
77
|
+
isOperational: boolean;
|
|
78
|
+
constructor(message: string, statusCode?: number, code?: string, context?: Record<string, any>, cause?: Error);
|
|
79
|
+
/**
|
|
80
|
+
* Wraps an existing error as the cause of a new `AppError`.
|
|
81
|
+
*
|
|
82
|
+
* This is a convenience factory for error chaining — it creates a new
|
|
83
|
+
* `AppError` whose `.cause` is set to the original error.
|
|
84
|
+
*
|
|
85
|
+
* @param originalError - The caught error to wrap
|
|
86
|
+
* @param message - Human-readable description of the higher-level failure
|
|
87
|
+
* @param statusCode - HTTP status code (default: 500)
|
|
88
|
+
* @param code - Machine-readable error code
|
|
89
|
+
* @param context - Additional context metadata
|
|
90
|
+
* @returns A new `AppError` with `originalError` as its cause
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* try {
|
|
95
|
+
* await db.query('SELECT ...');
|
|
96
|
+
* } catch (err) {
|
|
97
|
+
* throw AppError.wrap(err, 'Database query failed', 500, 'DB_ERROR');
|
|
98
|
+
* }
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
static wrap(originalError: Error, message: string, statusCode?: number, code?: string, context?: Record<string, any>): AppError;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Formats an error into a structured {@link ErrorDetails} object.
|
|
105
|
+
*
|
|
106
|
+
* When the error has a `.cause`, the cause chain is recursively formatted
|
|
107
|
+
* and included in the output.
|
|
108
|
+
*/
|
|
109
|
+
declare function formatError(error: Error | AppError, options?: ErrorHandlerOptions): ErrorDetails;
|
|
110
|
+
/**
|
|
111
|
+
* Handles errors with optional logging and formatting.
|
|
112
|
+
*/
|
|
113
|
+
declare function handleError(error: Error | AppError, options?: ErrorHandlerOptions): ErrorDetails;
|
|
114
|
+
/**
|
|
115
|
+
* Async error wrapper — catches errors from async route handlers
|
|
116
|
+
* and forwards them to Express's `next()` function.
|
|
117
|
+
*/
|
|
118
|
+
declare function asyncHandler<T extends (...args: any[]) => Promise<any>>(fn: T): T;
|
|
119
|
+
/**
|
|
120
|
+
* Express.js error handler middleware factory.
|
|
121
|
+
*
|
|
122
|
+
* Returns a standard Express error-handling middleware that formats
|
|
123
|
+
* the error and sends an appropriate JSON or string response.
|
|
124
|
+
*/
|
|
125
|
+
declare function expressErrorHandler(options?: ErrorHandlerOptions): (err: Error | AppError, req: any, res: any, next: any) => void;
|
|
126
|
+
/**
|
|
127
|
+
* Creates a standardized error response.
|
|
128
|
+
*/
|
|
129
|
+
declare function createErrorResponse(message: string, statusCode?: number, code?: string, context?: Record<string, any>): AppError;
|
|
130
|
+
/**
|
|
131
|
+
* Executes an async function with automatic retries on failure.
|
|
132
|
+
*
|
|
133
|
+
* Supports exponential, linear, and fixed backoff strategies with
|
|
134
|
+
* optional jitter, conditional retry predicates, and retry callbacks.
|
|
135
|
+
*
|
|
136
|
+
* If all retries are exhausted, the **last** error is thrown. The previous
|
|
137
|
+
* attempt errors are accessible via the error's `.cause` chain and the
|
|
138
|
+
* `attempts` property attached to the final error.
|
|
139
|
+
*
|
|
140
|
+
* @typeParam T - The return type of the async function
|
|
141
|
+
* @param fn - The async function to execute with retries
|
|
142
|
+
* @param options - Retry configuration options
|
|
143
|
+
* @returns The result of the successful function execution
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```ts
|
|
147
|
+
* const data = await withRetry(
|
|
148
|
+
* () => fetch('https://api.example.com/data').then(r => r.json()),
|
|
149
|
+
* {
|
|
150
|
+
* maxRetries: 5,
|
|
151
|
+
* backoff: 'exponential',
|
|
152
|
+
* initialDelay: 500,
|
|
153
|
+
* retryIf: (err) => err.message.includes('ECONNREFUSED'),
|
|
154
|
+
* onRetry: (err, attempt) => console.log(`Retry ${attempt}: ${err.message}`),
|
|
155
|
+
* }
|
|
156
|
+
* );
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
declare function withRetry<T>(fn: () => Promise<T>, options?: RetryOptions): Promise<T>;
|
|
160
|
+
/**
|
|
161
|
+
* Pre-built factory functions for common HTTP error responses.
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```ts
|
|
165
|
+
* throw Errors.notFound('User not found', { userId: 42 });
|
|
166
|
+
* throw Errors.unauthorized();
|
|
167
|
+
* throw Errors.tooManyRequests('Rate limit exceeded');
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
declare const Errors: ErrorMap;
|
|
171
|
+
declare const _default: {
|
|
172
|
+
AppError: typeof AppError;
|
|
173
|
+
formatError: typeof formatError;
|
|
174
|
+
handleError: typeof handleError;
|
|
175
|
+
asyncHandler: typeof asyncHandler;
|
|
176
|
+
expressErrorHandler: typeof expressErrorHandler;
|
|
177
|
+
createErrorResponse: typeof createErrorResponse;
|
|
178
|
+
withRetry: typeof withRetry;
|
|
179
|
+
Errors: ErrorMap;
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
export { AppError, type ErrorDetails, type ErrorFn, type ErrorHandlerOptions, type ErrorMap, Errors, type RetryOptions, asyncHandler, createErrorResponse, _default as default, expressErrorHandler, formatError, handleError, withRetry };
|
package/package.json
CHANGED
|
@@ -1,42 +1,77 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "error-shield",
|
|
3
|
-
"version": "2.0.
|
|
4
|
-
"description": "
|
|
5
|
-
"
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
|
-
"files": [
|
|
8
|
-
"dist",
|
|
9
|
-
"README.md"
|
|
10
|
-
],
|
|
11
|
-
"scripts": {
|
|
12
|
-
"build": "tsc",
|
|
13
|
-
"prepublishOnly": "npm run build",
|
|
14
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
15
|
-
},
|
|
3
|
+
"version": "2.0.1",
|
|
4
|
+
"description": "Comprehensive error handling utility for Node.js & Express.js — custom error classes, async handler wrapper, Express middleware, HTTP error creators, retry logic, error chaining, and TypeScript support.",
|
|
5
|
+
"type": "module",
|
|
16
6
|
"keywords": [
|
|
17
|
-
"error",
|
|
18
|
-
"error-shield",
|
|
19
7
|
"error-handling",
|
|
20
|
-
"express",
|
|
21
|
-
"middleware",
|
|
22
|
-
"typescript",
|
|
23
|
-
"nodejs",
|
|
24
|
-
"exception",
|
|
25
|
-
"error-management",
|
|
26
8
|
"error-handler",
|
|
9
|
+
"express-middleware",
|
|
10
|
+
"express-error-handler",
|
|
11
|
+
"nodejs",
|
|
12
|
+
"node-error",
|
|
13
|
+
"async-error-handler",
|
|
27
14
|
"custom-error",
|
|
28
|
-
"
|
|
15
|
+
"http-errors",
|
|
16
|
+
"error-middleware",
|
|
17
|
+
"typescript",
|
|
18
|
+
"error-class",
|
|
19
|
+
"api-errors",
|
|
20
|
+
"rest-api",
|
|
21
|
+
"error-formatting",
|
|
22
|
+
"error-logging",
|
|
23
|
+
"operational-errors",
|
|
24
|
+
"status-codes",
|
|
25
|
+
"express",
|
|
26
|
+
"error-creators",
|
|
27
|
+
"validation-error",
|
|
28
|
+
"app-error",
|
|
29
|
+
"error-utility",
|
|
30
|
+
"structured-errors",
|
|
31
|
+
"error-chaining",
|
|
32
|
+
"retry",
|
|
33
|
+
"retry-logic",
|
|
34
|
+
"exponential-backoff"
|
|
29
35
|
],
|
|
36
|
+
"homepage": "https://github.com/Gopinathgopi13/error-shield",
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "https://github.com/Gopinathgopi13/error-shield"
|
|
40
|
+
},
|
|
30
41
|
"author": "Gopinath Kathirvel",
|
|
31
42
|
"license": "ISC",
|
|
43
|
+
"main": "./dist/cjs/index.cjs",
|
|
44
|
+
"module": "./dist/esm/index.js",
|
|
45
|
+
"types": "./dist/types/index.d.ts",
|
|
46
|
+
"exports": {
|
|
47
|
+
".": {
|
|
48
|
+
"types": "./dist/types/index.d.ts",
|
|
49
|
+
"import": "./dist/esm/index.js",
|
|
50
|
+
"require": "./dist/cjs/index.cjs"
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"files": [
|
|
54
|
+
"dist",
|
|
55
|
+
"README.md",
|
|
56
|
+
"LICENSE"
|
|
57
|
+
],
|
|
58
|
+
"scripts": {
|
|
59
|
+
"build": "tsup",
|
|
60
|
+
"dev": "tsup --watch",
|
|
61
|
+
"test": "vitest run",
|
|
62
|
+
"test:watch": "vitest",
|
|
63
|
+
"test:coverage": "vitest run --coverage",
|
|
64
|
+
"lint": "tsc --noEmit",
|
|
65
|
+
"prepublishOnly": "npm run build"
|
|
66
|
+
},
|
|
32
67
|
"engines": {
|
|
33
|
-
"node": ">=
|
|
68
|
+
"node": ">=16.0.0"
|
|
34
69
|
},
|
|
35
70
|
"devDependencies": {
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"
|
|
40
|
-
"
|
|
71
|
+
"@types/node": "^20.0.0",
|
|
72
|
+
"tsup": "^8.0.0",
|
|
73
|
+
"typescript": "^5.3.0",
|
|
74
|
+
"vitest": "^2.0.0",
|
|
75
|
+
"@vitest/coverage-v8": "^2.0.0"
|
|
41
76
|
}
|
|
42
77
|
}
|