error-shield 1.1.0 โ†’ 1.2.0

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.
Files changed (3) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +334 -136
  3. package/package.json +1 -1
package/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2026 Gopinath Kathirvel
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/README.md CHANGED
@@ -1,36 +1,111 @@
1
- # Error Shield
1
+ <div align="center">
2
2
 
3
- A comprehensive error handling utility for Node.js & Express.js applications. Provides structured error handling, formatting, and Express.js middleware support.
3
+ # ๐Ÿ›ก๏ธ Error Shield
4
4
 
5
- ## Features
5
+ ### Elegant, structured error handling for Node.js & Express.js
6
6
 
7
- - ๐ŸŽฏ **Custom Error Class** - Extendable `AppError` class with status codes and context
8
- - ๐Ÿ“ฆ **Error Formatting** - Consistent error formatting with customizable options
9
- - ๐Ÿ”„ **Async Handler** - Wrapper for async functions to catch errors
10
- - ๐Ÿš€ **Express Middleware** - Ready-to-use Express.js error handler middleware
11
- - ๐Ÿ› ๏ธ **Error Creators** - Pre-built error creators for common HTTP status codes
12
- - ๐Ÿ“ **TypeScript Support** - Full TypeScript definitions included
7
+ [![npm version](https://img.shields.io/npm/v/error-shield?style=for-the-badge&color=cb3837&logo=npm&logoColor=white)](https://www.npmjs.com/package/error-shield)
8
+ [![License](https://img.shields.io/npm/l/error-shield?style=for-the-badge&color=blue)](https://github.com/Gopinathgopi13/error-shield/blob/main/LICENSE)
9
+ [![TypeScript](https://img.shields.io/badge/TypeScript-Ready-3178C6?style=for-the-badge&logo=typescript&logoColor=white)](https://www.typescriptlang.org/)
10
+ [![Node.js](https://img.shields.io/badge/Node.js-%3E%3D14-339933?style=for-the-badge&logo=node.js&logoColor=white)](https://nodejs.org/)
11
+ [![Downloads](https://img.shields.io/npm/dt/error-shield?style=for-the-badge&color=brightgreen&logo=npm)](https://www.npmjs.com/package/error-shield)
13
12
 
14
- ## Installation
13
+ **Stop writing repetitive error handling code.** Error Shield gives you a battle-tested toolkit โ€”
14
+ custom error classes, async wrappers, Express middleware, and 40+ HTTP error creators โ€” out of the box.
15
+
16
+ [Get Started](#-quick-start) ยท [API Reference](#-api-reference) ยท [Examples](#-usage-examples) ยท [Contributing](#-contributing)
17
+
18
+ </div>
19
+
20
+ ---
21
+
22
+ ## โœจ Why Error Shield?
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 `ErrorCreators` 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
+
32
+ ---
33
+
34
+ ## ๐Ÿ“ฆ Installation
15
35
 
16
36
  ```bash
37
+ # npm
17
38
  npm install error-shield
39
+
40
+ # yarn
41
+ yarn add error-shield
42
+
43
+ # pnpm
44
+ pnpm add error-shield
18
45
  ```
19
46
 
20
- ## Usage
47
+ ---
48
+
49
+ ## โšก Quick Start
21
50
 
22
- ### Basic Usage
51
+ Get up and running in **under 60 seconds**:
23
52
 
24
53
  ```javascript
25
- const { AppError, handleError, ErrorCreators } = require("error-shield");
54
+ const {
55
+ AppError,
56
+ handleError,
57
+ ErrorCreators,
58
+ expressErrorHandler,
59
+ asyncHandler,
60
+ } = require("error-shield");
61
+
62
+ // 1๏ธโƒฃ Throw meaningful errors
63
+ throw ErrorCreators.notFound("User not found", { userId: 42 });
64
+
65
+ // 2๏ธโƒฃ Handle & format any error
66
+ const details = handleError(new Error("Oops"), { includeStack: true });
67
+
68
+ // 3๏ธโƒฃ Plug into Express with one line
69
+ app.use(expressErrorHandler({ includeTimestamp: true }));
70
+ ```
71
+
72
+ That's it โ€” structured errors, formatted output, and Express integration with zero boilerplate. ๐ŸŽ‰
73
+
74
+ ---
75
+
76
+ ## ๐Ÿ“– Table of Contents
77
+
78
+ - [Why Error Shield?](#-why-error-shield)
79
+ - [Installation](#-installation)
80
+ - [Quick Start](#-quick-start)
81
+ - [Usage Examples](#-usage-examples)
82
+ - [Custom Errors with `AppError`](#1%EF%B8%8Fโƒฃ-custom-errors-with-apperror)
83
+ - [Error Creators](#2%EF%B8%8Fโƒฃ-error-creators)
84
+ - [Express.js Middleware](#3%EF%B8%8Fโƒฃ-expressjs-middleware)
85
+ - [Async Handler Wrapper](#4%EF%B8%8Fโƒฃ-async-handler-wrapper)
86
+ - [Custom Logger](#5%EF%B8%8Fโƒฃ-custom-logger)
87
+ - [API Reference](#-api-reference)
88
+ - [Error Creators โ€” Full Reference](#-error-creators--full-reference)
89
+ - [TypeScript Support](#-typescript-support)
90
+ - [Contributing](#-contributing)
91
+ - [License](#-license)
92
+
93
+ ---
94
+
95
+ ## ๐Ÿš€ Usage Examples
96
+
97
+ ### 1๏ธโƒฃ Custom Errors with `AppError`
98
+
99
+ Create rich, structured errors with status codes, error codes, and arbitrary context:
100
+
101
+ ```javascript
102
+ const { AppError, handleError } = require("error-shield");
26
103
 
27
- // Create a custom error
28
104
  const error = new AppError("Something went wrong", 500, "CUSTOM_ERROR", {
29
105
  userId: 123,
30
106
  action: "updateProfile",
31
107
  });
32
108
 
33
- // Handle and format error
34
109
  const errorDetails = handleError(error, {
35
110
  includeStack: true,
36
111
  includeTimestamp: true,
@@ -39,42 +114,83 @@ const errorDetails = handleError(error, {
39
114
  console.log(errorDetails);
40
115
  ```
41
116
 
42
- ### Using Error Creators
117
+ <details>
118
+ <summary>๐Ÿ“‹ <strong>Example Output</strong></summary>
119
+
120
+ ```json
121
+ {
122
+ "message": "Something went wrong",
123
+ "statusCode": 500,
124
+ "code": "CUSTOM_ERROR",
125
+ "context": {
126
+ "userId": 123,
127
+ "action": "updateProfile"
128
+ },
129
+ "isOperational": true,
130
+ "timestamp": "2026-02-24T10:30:00.000Z",
131
+ "stack": "Error: Something went wrong\n at ..."
132
+ }
133
+ ```
134
+
135
+ </details>
136
+
137
+ ---
138
+
139
+ ### 2๏ธโƒฃ Error Creators
140
+
141
+ Use pre-built error factories for common HTTP errors โ€” no need to memorize status codes:
43
142
 
44
143
  ```javascript
45
144
  const { ErrorCreators } = require("error-shield");
46
145
 
47
- // Bad Request (400)
146
+ // ๐Ÿ”ด 400 โ€” Bad Request
48
147
  throw ErrorCreators.badRequest("Invalid input provided", { field: "email" });
49
148
 
50
- // Unauthorized (401)
149
+ // ๐Ÿ”’ 401 โ€” Unauthorized
51
150
  throw ErrorCreators.unauthorized("Authentication required");
52
151
 
53
- // Not Found (404)
152
+ // ๐Ÿ” 404 โ€” Not Found
54
153
  throw ErrorCreators.notFound("User not found", { userId: 123 });
55
154
 
56
- // Validation Error (422)
155
+ // โœ๏ธ 422 โ€” Validation Error
57
156
  throw ErrorCreators.validationError("Email is required", { field: "email" });
157
+
158
+ // ๐Ÿšฆ 429 โ€” Too Many Requests
159
+ throw ErrorCreators.tooManyRequests("Rate limit exceeded", { retryAfter: 60 });
160
+
161
+ // ๐Ÿ’ฅ 500 โ€” Internal Server Error
162
+ throw ErrorCreators.internalServerError("Unexpected failure");
58
163
  ```
59
164
 
60
- ### Express.js Middleware
165
+ ---
166
+
167
+ ### 3๏ธโƒฃ Express.js Middleware
168
+
169
+ Plug in a production-ready error handler with a single line:
61
170
 
62
171
  ```javascript
63
172
  const express = require("express");
64
- const { expressErrorHandler, ErrorCreators } = require("error-shield");
173
+ const {
174
+ expressErrorHandler,
175
+ asyncHandler,
176
+ ErrorCreators,
177
+ } = require("error-shield");
65
178
 
66
179
  const app = express();
67
180
 
68
- // Your routes
69
- app.get("/users/:id", async (req, res, next) => {
70
- const user = await getUserById(req.params.id);
71
- if (!user) {
72
- throw ErrorCreators.notFound("User not found", { userId: req.params.id });
73
- }
74
- res.json(user);
75
- });
181
+ // Your routes โ€” errors are automatically caught & forwarded
182
+ app.get(
183
+ "/users/:id",
184
+ asyncHandler(async (req, res) => {
185
+ const user = await getUserById(req.params.id);
186
+ if (!user) {
187
+ throw ErrorCreators.notFound("User not found", { userId: req.params.id });
188
+ }
189
+ res.json(user);
190
+ }),
191
+ );
76
192
 
77
- // Error handler middleware (must be last)
193
+ // โฌ‡๏ธ Error handler middleware (must be last)
78
194
  app.use(
79
195
  expressErrorHandler({
80
196
  includeStack: process.env.NODE_ENV !== "production",
@@ -82,15 +198,31 @@ app.use(
82
198
  }),
83
199
  );
84
200
 
85
- app.listen(3000);
201
+ app.listen(3000, () => console.log("๐Ÿš€ Server running on port 3000"));
86
202
  ```
87
203
 
88
- ### Async Handler Wrapper
204
+ > **๐Ÿ’ก Tip:** Combine `asyncHandler` with `expressErrorHandler` for completely boilerplate-free async route error handling.
205
+
206
+ ---
207
+
208
+ ### 4๏ธโƒฃ Async Handler Wrapper
209
+
210
+ Eliminate `try/catch` blocks in your async route handlers:
89
211
 
90
212
  ```javascript
91
213
  const { asyncHandler } = require("error-shield");
92
214
 
93
- // Wrap async route handlers
215
+ // โŒ Without asyncHandler
216
+ app.get("/api/data", async (req, res, next) => {
217
+ try {
218
+ const data = await fetchData();
219
+ res.json(data);
220
+ } catch (err) {
221
+ next(err); // easy to forget!
222
+ }
223
+ });
224
+
225
+ // โœ… With asyncHandler โ€” clean & safe
94
226
  app.get(
95
227
  "/api/data",
96
228
  asyncHandler(async (req, res) => {
@@ -100,25 +232,31 @@ app.get(
100
232
  );
101
233
  ```
102
234
 
103
- ### Custom Logger
235
+ ---
236
+
237
+ ### 5๏ธโƒฃ Custom Logger
238
+
239
+ Attach your own logging logic โ€” send errors to Sentry, Datadog, or any external service:
104
240
 
105
241
  ```javascript
106
242
  const { handleError } = require("error-shield");
107
243
 
108
244
  const errorDetails = handleError(error, {
109
- logger: (errorDetails) => {
110
- // Custom logging logic
111
- console.error("Error occurred:", errorDetails);
112
- // Send to logging service, etc.
245
+ logger: (details) => {
246
+ console.error("[ERROR]", details.message);
247
+ // ๐Ÿ“ค Send to your logging service
248
+ Sentry.captureException(details);
113
249
  },
114
250
  });
115
251
  ```
116
252
 
117
- ## API Reference
253
+ ---
254
+
255
+ ## ๐Ÿ“š API Reference
118
256
 
119
- ### `AppError`
257
+ ### `AppError` class
120
258
 
121
- Custom error class that extends the native `Error` class.
259
+ > Extends the native `Error` class with structured metadata.
122
260
 
123
261
  ```typescript
124
262
  class AppError extends Error {
@@ -129,127 +267,187 @@ class AppError extends Error {
129
267
  }
130
268
  ```
131
269
 
132
- **Constructor:**
270
+ | Parameter | Type | Default | Description |
271
+ | :----------- | :-------------------- | :-----: | :--------------------------- |
272
+ | `message` | `string` | โ€” | Error message |
273
+ | `statusCode` | `number` | `500` | HTTP status code |
274
+ | `code` | `string` | โ€” | Machine-readable error code |
275
+ | `context` | `Record<string, any>` | โ€” | Additional debugging context |
133
276
 
134
- - `message: string` - Error message
135
- - `statusCode: number` - HTTP status code (default: 500)
136
- - `code?: string` - Error code
137
- - `context?: Record<string, any>` - Additional context
277
+ ---
138
278
 
139
279
  ### `formatError(error, options?)`
140
280
 
141
- Formats an error into a structured object.
142
-
143
- **Parameters:**
281
+ > Formats any error into a consistent `ErrorDetails` object.
144
282
 
145
- - `error: Error | AppError` - The error to format
146
- - `options: ErrorHandlerOptions` - Formatting options
283
+ | Parameter | Type | Description |
284
+ | :-------- | :-------------------- | :------------------ |
285
+ | `error` | `Error \| AppError` | The error to format |
286
+ | `options` | `ErrorHandlerOptions` | Formatting options |
147
287
 
148
288
  **Returns:** `ErrorDetails`
149
289
 
150
- ### `handleError(error, options?)`
290
+ ---
151
291
 
152
- Handles errors with optional logging and formatting.
292
+ ### `handleError(error, options?)`
153
293
 
154
- **Parameters:**
294
+ > Handles errors with optional logging and formatting.
155
295
 
156
- - `error: Error | AppError` - The error to handle
157
- - `options: ErrorHandlerOptions` - Handler options
296
+ | Parameter | Type | Description |
297
+ | :-------- | :-------------------- | :---------------------------------------------------------------------- |
298
+ | `error` | `Error \| AppError` | The error to handle |
299
+ | `options` | `ErrorHandlerOptions` | Handler options (includes `logger`, `includeStack`, `includeTimestamp`) |
158
300
 
159
301
  **Returns:** `ErrorDetails`
160
302
 
303
+ ---
304
+
161
305
  ### `asyncHandler(fn)`
162
306
 
163
- Wraps an async function to catch errors.
307
+ > Wraps an async Express route handler to automatically catch rejected promises.
164
308
 
165
- **Parameters:**
309
+ | Parameter | Type | Description |
310
+ | :-------- | :--------------------------------- | :--------------------------- |
311
+ | `fn` | `(req, res, next) => Promise<any>` | Async route handler function |
166
312
 
167
- - `fn: Function` - Async function to wrap
313
+ **Returns:** Wrapped Express middleware function
168
314
 
169
- **Returns:** Wrapped function
315
+ ---
170
316
 
171
317
  ### `expressErrorHandler(options?)`
172
318
 
173
- Creates an Express.js error handler middleware.
174
-
175
- **Parameters:**
176
-
177
- - `options: ErrorHandlerOptions` - Handler options
178
-
179
- **Returns:** Express middleware function
180
-
181
- ### `ErrorCreators`
182
-
183
- Pre-built error creators for all standard HTTP error status codes:
184
-
185
- **4xx Client Errors:**
186
-
187
- | Method | Code | Default Message |
188
- | ------------------------------------------------- | ---- | ------------------------------- |
189
- | `badRequest(message, context?)` | 400 | _(required)_ |
190
- | `unauthorized(message?, context?)` | 401 | Unauthorized |
191
- | `paymentRequired(message?, context?)` | 402 | Payment Required |
192
- | `forbidden(message?, context?)` | 403 | Forbidden |
193
- | `notFound(message?, context?)` | 404 | Not Found |
194
- | `methodNotAllowed(message?, context?)` | 405 | Method Not Allowed |
195
- | `notAcceptable(message?, context?)` | 406 | Not Acceptable |
196
- | `proxyAuthRequired(message?, context?)` | 407 | Proxy Authentication Required |
197
- | `requestTimeout(message?, context?)` | 408 | Request Timeout |
198
- | `conflict(message, context?)` | 409 | _(required)_ |
199
- | `gone(message?, context?)` | 410 | Gone |
200
- | `lengthRequired(message?, context?)` | 411 | Length Required |
201
- | `preconditionFailed(message?, context?)` | 412 | Precondition Failed |
202
- | `payloadTooLarge(message?, context?)` | 413 | Payload Too Large |
203
- | `uriTooLong(message?, context?)` | 414 | URI Too Long |
204
- | `unsupportedMediaType(message?, context?)` | 415 | Unsupported Media Type |
205
- | `rangeNotSatisfiable(message?, context?)` | 416 | Range Not Satisfiable |
206
- | `expectationFailed(message?, context?)` | 417 | Expectation Failed |
207
- | `imATeapot(message?, context?)` | 418 | I'm a Teapot |
208
- | `misdirectedRequest(message?, context?)` | 421 | Misdirected Request |
209
- | `unprocessableEntity(message?, context?)` | 422 | Unprocessable Entity |
210
- | `validationError(message, context?)` | 422 | _(required)_ |
211
- | `locked(message?, context?)` | 423 | Locked |
212
- | `failedDependency(message?, context?)` | 424 | Failed Dependency |
213
- | `tooEarly(message?, context?)` | 425 | Too Early |
214
- | `upgradeRequired(message?, context?)` | 426 | Upgrade Required |
215
- | `preconditionRequired(message?, context?)` | 428 | Precondition Required |
216
- | `tooManyRequests(message?, context?)` | 429 | Too Many Requests |
217
- | `requestHeaderFieldsTooLarge(message?, context?)` | 431 | Request Header Fields Too Large |
218
- | `unavailableForLegalReasons(message?, context?)` | 451 | Unavailable For Legal Reasons |
219
-
220
- **5xx Server Errors:**
221
-
222
- | Method | Code | Default Message |
223
- | --------------------------------------------------- | ---- | ------------------------------- |
224
- | `internalServerError(message?, context?)` | 500 | Internal Server Error |
225
- | `notImplemented(message?, context?)` | 501 | Not Implemented |
226
- | `badGateway(message?, context?)` | 502 | Bad Gateway |
227
- | `serviceUnavailable(message?, context?)` | 503 | Service Unavailable |
228
- | `gatewayTimeout(message?, context?)` | 504 | Gateway Timeout |
229
- | `httpVersionNotSupported(message?, context?)` | 505 | HTTP Version Not Supported |
230
- | `variantAlsoNegotiates(message?, context?)` | 506 | Variant Also Negotiates |
231
- | `insufficientStorage(message?, context?)` | 507 | Insufficient Storage |
232
- | `loopDetected(message?, context?)` | 508 | Loop Detected |
233
- | `bandwidthLimitExceeded(message?, context?)` | 509 | Bandwidth Limit Exceeded |
234
- | `notExtended(message?, context?)` | 510 | Not Extended |
235
- | `networkAuthenticationRequired(message?, context?)` | 511 | Network Authentication Required |
236
- | `networkConnectTimeout(message?, context?)` | 599 | Network Connect Timeout |
237
-
238
- ## TypeScript Support
239
-
240
- This package includes full TypeScript definitions:
319
+ > Creates an Express.js error-handling middleware.
320
+
321
+ | Parameter | Type | Description |
322
+ | :-------- | :-------------------- | :-------------- |
323
+ | `options` | `ErrorHandlerOptions` | Handler options |
324
+
325
+ **Returns:** Express error middleware `(err, req, res, next) => void`
326
+
327
+ ---
328
+
329
+ ## ๐Ÿ—‚๏ธ Error Creators โ€” Full Reference
330
+
331
+ Pre-built factory methods for **all standard HTTP error codes**. Every method returns an `AppError` instance.
332
+
333
+ ```javascript
334
+ // Signature for all creators:
335
+ ErrorCreators.methodName(message?, context?)
336
+ // โ†’ Returns: AppError
337
+ ```
338
+
339
+ <details>
340
+ <summary>๐ŸŸ  <strong>4xx Client Errors</strong> <em>(click to expand)</em></summary>
341
+
342
+ | Method | Code | Default Message |
343
+ | :------------------------------------------------ | :---: | :------------------------------ |
344
+ | `badRequest(message, context?)` | `400` | _(required)_ |
345
+ | `unauthorized(message?, context?)` | `401` | Unauthorized |
346
+ | `paymentRequired(message?, context?)` | `402` | Payment Required |
347
+ | `forbidden(message?, context?)` | `403` | Forbidden |
348
+ | `notFound(message?, context?)` | `404` | Not Found |
349
+ | `methodNotAllowed(message?, context?)` | `405` | Method Not Allowed |
350
+ | `notAcceptable(message?, context?)` | `406` | Not Acceptable |
351
+ | `proxyAuthRequired(message?, context?)` | `407` | Proxy Authentication Required |
352
+ | `requestTimeout(message?, context?)` | `408` | Request Timeout |
353
+ | `conflict(message, context?)` | `409` | _(required)_ |
354
+ | `gone(message?, context?)` | `410` | Gone |
355
+ | `lengthRequired(message?, context?)` | `411` | Length Required |
356
+ | `preconditionFailed(message?, context?)` | `412` | Precondition Failed |
357
+ | `payloadTooLarge(message?, context?)` | `413` | Payload Too Large |
358
+ | `uriTooLong(message?, context?)` | `414` | URI Too Long |
359
+ | `unsupportedMediaType(message?, context?)` | `415` | Unsupported Media Type |
360
+ | `rangeNotSatisfiable(message?, context?)` | `416` | Range Not Satisfiable |
361
+ | `expectationFailed(message?, context?)` | `417` | Expectation Failed |
362
+ | `imATeapot(message?, context?)` | `418` | I'm a Teapot |
363
+ | `misdirectedRequest(message?, context?)` | `421` | Misdirected Request |
364
+ | `unprocessableEntity(message?, context?)` | `422` | Unprocessable Entity |
365
+ | `validationError(message, context?)` | `422` | _(required)_ |
366
+ | `locked(message?, context?)` | `423` | Locked |
367
+ | `failedDependency(message?, context?)` | `424` | Failed Dependency |
368
+ | `tooEarly(message?, context?)` | `425` | Too Early |
369
+ | `upgradeRequired(message?, context?)` | `426` | Upgrade Required |
370
+ | `preconditionRequired(message?, context?)` | `428` | Precondition Required |
371
+ | `tooManyRequests(message?, context?)` | `429` | Too Many Requests |
372
+ | `requestHeaderFieldsTooLarge(message?, context?)` | `431` | Request Header Fields Too Large |
373
+ | `unavailableForLegalReasons(message?, context?)` | `451` | Unavailable For Legal Reasons |
374
+
375
+ </details>
376
+
377
+ <details>
378
+ <summary>๐Ÿ”ด <strong>5xx Server Errors</strong> <em>(click to expand)</em></summary>
379
+
380
+ | Method | Code | Default Message |
381
+ | :-------------------------------------------------- | :---: | :------------------------------ |
382
+ | `internalServerError(message?, context?)` | `500` | Internal Server Error |
383
+ | `notImplemented(message?, context?)` | `501` | Not Implemented |
384
+ | `badGateway(message?, context?)` | `502` | Bad Gateway |
385
+ | `serviceUnavailable(message?, context?)` | `503` | Service Unavailable |
386
+ | `gatewayTimeout(message?, context?)` | `504` | Gateway Timeout |
387
+ | `httpVersionNotSupported(message?, context?)` | `505` | HTTP Version Not Supported |
388
+ | `variantAlsoNegotiates(message?, context?)` | `506` | Variant Also Negotiates |
389
+ | `insufficientStorage(message?, context?)` | `507` | Insufficient Storage |
390
+ | `loopDetected(message?, context?)` | `508` | Loop Detected |
391
+ | `bandwidthLimitExceeded(message?, context?)` | `509` | Bandwidth Limit Exceeded |
392
+ | `notExtended(message?, context?)` | `510` | Not Extended |
393
+ | `networkAuthenticationRequired(message?, context?)` | `511` | Network Authentication Required |
394
+ | `networkConnectTimeout(message?, context?)` | `599` | Network Connect Timeout |
395
+
396
+ </details>
397
+
398
+ ---
399
+
400
+ ## ๐ŸŸฆ TypeScript Support
401
+
402
+ Error Shield ships with **full TypeScript declarations** โ€” zero extra config needed.
241
403
 
242
404
  ```typescript
243
- import { AppError, ErrorCreators, handleError } from "error-shield";
405
+ import {
406
+ AppError,
407
+ ErrorCreators,
408
+ handleError,
409
+ asyncHandler,
410
+ expressErrorHandler,
411
+ type ErrorDetails,
412
+ type ErrorHandlerOptions,
413
+ } from "error-shield";
414
+
415
+ // Fully typed error creation
416
+ const error: AppError = ErrorCreators.notFound("User not found", {
417
+ userId: 42,
418
+ });
244
419
 
245
- const error: AppError = ErrorCreators.notFound("User not found");
246
- const details = handleError(error);
420
+ // Typed error details
421
+ const details: ErrorDetails = handleError(error, {
422
+ includeStack: true,
423
+ includeTimestamp: true,
424
+ });
247
425
  ```
248
426
 
249
- ## License
427
+ ---
428
+
429
+ ## ๐Ÿค Contributing
430
+
431
+ Contributions, issues, and feature requests are welcome!
432
+
433
+ 1. **Fork** the repository
434
+ 2. **Create** your feature branch โ€” `git checkout -b feature/amazing-feature`
435
+ 3. **Commit** your changes โ€” `git commit -m "feat: add amazing feature"`
436
+ 4. **Push** to the branch โ€” `git push origin feature/amazing-feature`
437
+ 5. **Open** a Pull Request
438
+
439
+ ---
440
+
441
+ ## ๐Ÿ“„ License
442
+
443
+ This project is licensed under the [ISC License](https://opensource.org/licenses/ISC).
444
+
445
+ ---
446
+
447
+ <div align="center">
250
448
 
251
- ISC
449
+ Made with โค๏ธ by **[Gopinath Kathirvel](https://github.com/Gopinathgopi13)**
252
450
 
253
- ## Author
451
+ โญ **If you found this useful, give it a star on [GitHub](https://github.com/Gopinathgopi13/error-shield)!** โญ
254
452
 
255
- Gopinath Kathirvel
453
+ </div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "error-shield",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
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",