error-shield 1.2.1 → 1.2.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/README.md +22 -26
- 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/package.json +5 -1
package/README.md
CHANGED
|
@@ -21,13 +21,13 @@ custom error classes, async wrappers, Express middleware, and 40+ HTTP error cre
|
|
|
21
21
|
|
|
22
22
|
## ✨ Why Error Shield?
|
|
23
23
|
|
|
24
|
-
| Pain Point | How Error Shield Helps
|
|
25
|
-
| :------------------------------------------------ |
|
|
26
|
-
| ❌ Inconsistent error responses across routes | ✅ Uniform `ErrorDetails` structure everywhere
|
|
27
|
-
| ❌ Boilerplate `try/catch` in every async handler | ✅ `asyncHandler()` wraps it for you
|
|
28
|
-
| ❌ Manually setting status codes & messages | ✅ 40+ pre-built `
|
|
29
|
-
| ❌ No context attached to errors for debugging | ✅ `AppError` carries structured `context` data
|
|
30
|
-
| ❌ Missing TypeScript types for errors | ✅ Full type definitions included
|
|
24
|
+
| Pain Point | How Error Shield Helps |
|
|
25
|
+
| :------------------------------------------------ | :---------------------------------------------- |
|
|
26
|
+
| ❌ Inconsistent error responses across routes | ✅ Uniform `ErrorDetails` structure everywhere |
|
|
27
|
+
| ❌ Boilerplate `try/catch` in every async handler | ✅ `asyncHandler()` wraps it for you |
|
|
28
|
+
| ❌ Manually setting status codes & messages | ✅ 40+ pre-built `Errors` with correct codes |
|
|
29
|
+
| ❌ No context attached to errors for debugging | ✅ `AppError` carries structured `context` data |
|
|
30
|
+
| ❌ Missing TypeScript types for errors | ✅ Full type definitions included |
|
|
31
31
|
|
|
32
32
|
---
|
|
33
33
|
|
|
@@ -54,13 +54,13 @@ Get up and running in **under 60 seconds**:
|
|
|
54
54
|
const {
|
|
55
55
|
AppError,
|
|
56
56
|
handleError,
|
|
57
|
-
|
|
57
|
+
Errors,
|
|
58
58
|
expressErrorHandler,
|
|
59
59
|
asyncHandler,
|
|
60
60
|
} = require("error-shield");
|
|
61
61
|
|
|
62
62
|
// 1️⃣ Throw meaningful errors
|
|
63
|
-
throw
|
|
63
|
+
throw Errors.notFound("User not found", { userId: 42 });
|
|
64
64
|
|
|
65
65
|
// 2️⃣ Handle & format any error
|
|
66
66
|
const details = handleError(new Error("Oops"), { includeStack: true });
|
|
@@ -141,25 +141,25 @@ console.log(errorDetails);
|
|
|
141
141
|
Use pre-built error factories for common HTTP errors — no need to memorize status codes:
|
|
142
142
|
|
|
143
143
|
```javascript
|
|
144
|
-
const {
|
|
144
|
+
const { Errors } = require("error-shield");
|
|
145
145
|
|
|
146
146
|
// 🔴 400 — Bad Request
|
|
147
|
-
throw
|
|
147
|
+
throw Errors.badRequest("Invalid input provided", { field: "email" });
|
|
148
148
|
|
|
149
149
|
// 🔒 401 — Unauthorized
|
|
150
|
-
throw
|
|
150
|
+
throw Errors.unauthorized("Authentication required");
|
|
151
151
|
|
|
152
152
|
// 🔍 404 — Not Found
|
|
153
|
-
throw
|
|
153
|
+
throw Errors.notFound("User not found", { userId: 123 });
|
|
154
154
|
|
|
155
155
|
// ✏️ 422 — Validation Error
|
|
156
|
-
throw
|
|
156
|
+
throw Errors.validationError("Email is required", { field: "email" });
|
|
157
157
|
|
|
158
158
|
// 🚦 429 — Too Many Requests
|
|
159
|
-
throw
|
|
159
|
+
throw Errors.tooManyRequests("Rate limit exceeded", { retryAfter: 60 });
|
|
160
160
|
|
|
161
161
|
// 💥 500 — Internal Server Error
|
|
162
|
-
throw
|
|
162
|
+
throw Errors.internalServerError("Unexpected failure");
|
|
163
163
|
```
|
|
164
164
|
|
|
165
165
|
---
|
|
@@ -170,11 +170,7 @@ Plug in a production-ready error handler with a single line:
|
|
|
170
170
|
|
|
171
171
|
```javascript
|
|
172
172
|
const express = require("express");
|
|
173
|
-
const {
|
|
174
|
-
expressErrorHandler,
|
|
175
|
-
asyncHandler,
|
|
176
|
-
ErrorCreators,
|
|
177
|
-
} = require("error-shield");
|
|
173
|
+
const { expressErrorHandler, asyncHandler, Errors } = require("error-shield");
|
|
178
174
|
|
|
179
175
|
const app = express();
|
|
180
176
|
|
|
@@ -184,7 +180,7 @@ app.get(
|
|
|
184
180
|
asyncHandler(async (req, res) => {
|
|
185
181
|
const user = await getUserById(req.params.id);
|
|
186
182
|
if (!user) {
|
|
187
|
-
throw
|
|
183
|
+
throw Errors.notFound("User not found", { userId: req.params.id });
|
|
188
184
|
}
|
|
189
185
|
res.json(user);
|
|
190
186
|
}),
|
|
@@ -332,7 +328,7 @@ Pre-built factory methods for **all standard HTTP error codes**. Every method re
|
|
|
332
328
|
|
|
333
329
|
```javascript
|
|
334
330
|
// Signature for all creators:
|
|
335
|
-
|
|
331
|
+
Errors.methodName(message?, context?)
|
|
336
332
|
// → Returns: AppError
|
|
337
333
|
```
|
|
338
334
|
|
|
@@ -404,7 +400,7 @@ Error Shield ships with **full TypeScript declarations** — zero extra config n
|
|
|
404
400
|
```typescript
|
|
405
401
|
import {
|
|
406
402
|
AppError,
|
|
407
|
-
|
|
403
|
+
Errors,
|
|
408
404
|
handleError,
|
|
409
405
|
asyncHandler,
|
|
410
406
|
expressErrorHandler,
|
|
@@ -413,7 +409,7 @@ import {
|
|
|
413
409
|
} from "error-shield";
|
|
414
410
|
|
|
415
411
|
// Fully typed error creation
|
|
416
|
-
const error: AppError =
|
|
412
|
+
const error: AppError = Errors.notFound("User not found", {
|
|
417
413
|
userId: 42,
|
|
418
414
|
});
|
|
419
415
|
|
|
@@ -438,7 +434,7 @@ Contributions, issues, and feature requests are welcome!
|
|
|
438
434
|
|
|
439
435
|
---
|
|
440
436
|
|
|
441
|
-
## 📄 License
|
|
437
|
+
## 📄 License
|
|
442
438
|
|
|
443
439
|
This project is licensed under the [ISC License](https://opensource.org/licenses/ISC).
|
|
444
440
|
|
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.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AE,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;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G,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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "error-shield",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
4
4
|
"description": "Comprehensive error handling utility for Node.js & Express.js — custom error classes, async handler wrapper, Express middleware, HTTP error creators, and TypeScript support.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"error-handling",
|
|
@@ -37,6 +37,10 @@
|
|
|
37
37
|
"license": "ISC",
|
|
38
38
|
"main": "dist/index.js",
|
|
39
39
|
"types": "dist/index.d.ts",
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "tsc",
|
|
42
|
+
"start": "node dist/index.js"
|
|
43
|
+
},
|
|
40
44
|
"engines": {
|
|
41
45
|
"node": ">=14.0.0"
|
|
42
46
|
}
|