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 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 `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
+
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
+ Errors,
58
+ expressErrorHandler,
59
+ asyncHandler,
60
+ } = require("error-shield");
61
+
62
+ // 1๏ธโƒฃ Throw meaningful errors
63
+ throw Errors.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,79 @@ 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
- const { ErrorCreators } = require("error-shield");
144
+ const { Errors } = require("error-shield");
46
145
 
47
- // Bad Request (400)
48
- throw ErrorCreators.badRequest("Invalid input provided", { field: "email" });
146
+ // ๐Ÿ”ด 400 โ€” Bad Request
147
+ throw Errors.badRequest("Invalid input provided", { field: "email" });
49
148
 
50
- // Unauthorized (401)
51
- throw ErrorCreators.unauthorized("Authentication required");
149
+ // ๐Ÿ”’ 401 โ€” Unauthorized
150
+ throw Errors.unauthorized("Authentication required");
52
151
 
53
- // Not Found (404)
54
- throw ErrorCreators.notFound("User not found", { userId: 123 });
152
+ // ๐Ÿ” 404 โ€” Not Found
153
+ throw Errors.notFound("User not found", { userId: 123 });
55
154
 
56
- // Validation Error (422)
57
- throw ErrorCreators.validationError("Email is required", { field: "email" });
155
+ // โœ๏ธ 422 โ€” Validation Error
156
+ throw Errors.validationError("Email is required", { field: "email" });
157
+
158
+ // ๐Ÿšฆ 429 โ€” Too Many Requests
159
+ throw Errors.tooManyRequests("Rate limit exceeded", { retryAfter: 60 });
160
+
161
+ // ๐Ÿ’ฅ 500 โ€” Internal Server Error
162
+ throw Errors.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 { expressErrorHandler, asyncHandler, Errors } = require("error-shield");
65
174
 
66
175
  const app = express();
67
176
 
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
- });
177
+ // Your routes โ€” errors are automatically caught & forwarded
178
+ app.get(
179
+ "/users/:id",
180
+ asyncHandler(async (req, res) => {
181
+ const user = await getUserById(req.params.id);
182
+ if (!user) {
183
+ throw Errors.notFound("User not found", { userId: req.params.id });
184
+ }
185
+ res.json(user);
186
+ }),
187
+ );
76
188
 
77
- // Error handler middleware (must be last)
189
+ // โฌ‡๏ธ Error handler middleware (must be last)
78
190
  app.use(
79
191
  expressErrorHandler({
80
192
  includeStack: process.env.NODE_ENV !== "production",
@@ -82,15 +194,31 @@ app.use(
82
194
  }),
83
195
  );
84
196
 
85
- app.listen(3000);
197
+ app.listen(3000, () => console.log("๐Ÿš€ Server running on port 3000"));
86
198
  ```
87
199
 
88
- ### Async Handler Wrapper
200
+ > **๐Ÿ’ก Tip:** Combine `asyncHandler` with `expressErrorHandler` for completely boilerplate-free async route error handling.
201
+
202
+ ---
203
+
204
+ ### 4๏ธโƒฃ Async Handler Wrapper
205
+
206
+ Eliminate `try/catch` blocks in your async route handlers:
89
207
 
90
208
  ```javascript
91
209
  const { asyncHandler } = require("error-shield");
92
210
 
93
- // Wrap async route handlers
211
+ // โŒ Without asyncHandler
212
+ app.get("/api/data", async (req, res, next) => {
213
+ try {
214
+ const data = await fetchData();
215
+ res.json(data);
216
+ } catch (err) {
217
+ next(err); // easy to forget!
218
+ }
219
+ });
220
+
221
+ // โœ… With asyncHandler โ€” clean & safe
94
222
  app.get(
95
223
  "/api/data",
96
224
  asyncHandler(async (req, res) => {
@@ -100,25 +228,31 @@ app.get(
100
228
  );
101
229
  ```
102
230
 
103
- ### Custom Logger
231
+ ---
232
+
233
+ ### 5๏ธโƒฃ Custom Logger
234
+
235
+ Attach your own logging logic โ€” send errors to Sentry, Datadog, or any external service:
104
236
 
105
237
  ```javascript
106
238
  const { handleError } = require("error-shield");
107
239
 
108
240
  const errorDetails = handleError(error, {
109
- logger: (errorDetails) => {
110
- // Custom logging logic
111
- console.error("Error occurred:", errorDetails);
112
- // Send to logging service, etc.
241
+ logger: (details) => {
242
+ console.error("[ERROR]", details.message);
243
+ // ๐Ÿ“ค Send to your logging service
244
+ Sentry.captureException(details);
113
245
  },
114
246
  });
115
247
  ```
116
248
 
117
- ## API Reference
249
+ ---
250
+
251
+ ## ๐Ÿ“š API Reference
118
252
 
119
- ### `AppError`
253
+ ### `AppError` class
120
254
 
121
- Custom error class that extends the native `Error` class.
255
+ > Extends the native `Error` class with structured metadata.
122
256
 
123
257
  ```typescript
124
258
  class AppError extends Error {
@@ -129,127 +263,187 @@ class AppError extends Error {
129
263
  }
130
264
  ```
131
265
 
132
- **Constructor:**
266
+ | Parameter | Type | Default | Description |
267
+ | :----------- | :-------------------- | :-----: | :--------------------------- |
268
+ | `message` | `string` | โ€” | Error message |
269
+ | `statusCode` | `number` | `500` | HTTP status code |
270
+ | `code` | `string` | โ€” | Machine-readable error code |
271
+ | `context` | `Record<string, any>` | โ€” | Additional debugging context |
133
272
 
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
273
+ ---
138
274
 
139
275
  ### `formatError(error, options?)`
140
276
 
141
- Formats an error into a structured object.
142
-
143
- **Parameters:**
277
+ > Formats any error into a consistent `ErrorDetails` object.
144
278
 
145
- - `error: Error | AppError` - The error to format
146
- - `options: ErrorHandlerOptions` - Formatting options
279
+ | Parameter | Type | Description |
280
+ | :-------- | :-------------------- | :------------------ |
281
+ | `error` | `Error \| AppError` | The error to format |
282
+ | `options` | `ErrorHandlerOptions` | Formatting options |
147
283
 
148
284
  **Returns:** `ErrorDetails`
149
285
 
150
- ### `handleError(error, options?)`
286
+ ---
151
287
 
152
- Handles errors with optional logging and formatting.
288
+ ### `handleError(error, options?)`
153
289
 
154
- **Parameters:**
290
+ > Handles errors with optional logging and formatting.
155
291
 
156
- - `error: Error | AppError` - The error to handle
157
- - `options: ErrorHandlerOptions` - Handler options
292
+ | Parameter | Type | Description |
293
+ | :-------- | :-------------------- | :---------------------------------------------------------------------- |
294
+ | `error` | `Error \| AppError` | The error to handle |
295
+ | `options` | `ErrorHandlerOptions` | Handler options (includes `logger`, `includeStack`, `includeTimestamp`) |
158
296
 
159
297
  **Returns:** `ErrorDetails`
160
298
 
299
+ ---
300
+
161
301
  ### `asyncHandler(fn)`
162
302
 
163
- Wraps an async function to catch errors.
303
+ > Wraps an async Express route handler to automatically catch rejected promises.
164
304
 
165
- **Parameters:**
305
+ | Parameter | Type | Description |
306
+ | :-------- | :--------------------------------- | :--------------------------- |
307
+ | `fn` | `(req, res, next) => Promise<any>` | Async route handler function |
166
308
 
167
- - `fn: Function` - Async function to wrap
309
+ **Returns:** Wrapped Express middleware function
168
310
 
169
- **Returns:** Wrapped function
311
+ ---
170
312
 
171
313
  ### `expressErrorHandler(options?)`
172
314
 
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:
315
+ > Creates an Express.js error-handling middleware.
316
+
317
+ | Parameter | Type | Description |
318
+ | :-------- | :-------------------- | :-------------- |
319
+ | `options` | `ErrorHandlerOptions` | Handler options |
320
+
321
+ **Returns:** Express error middleware `(err, req, res, next) => void`
322
+
323
+ ---
324
+
325
+ ## ๐Ÿ—‚๏ธ Error Creators โ€” Full Reference
326
+
327
+ Pre-built factory methods for **all standard HTTP error codes**. Every method returns an `AppError` instance.
328
+
329
+ ```javascript
330
+ // Signature for all creators:
331
+ Errors.methodName(message?, context?)
332
+ // โ†’ Returns: AppError
333
+ ```
334
+
335
+ <details>
336
+ <summary>๐ŸŸ  <strong>4xx Client Errors</strong> <em>(click to expand)</em></summary>
337
+
338
+ | Method | Code | Default Message |
339
+ | :------------------------------------------------ | :---: | :------------------------------ |
340
+ | `badRequest(message, context?)` | `400` | _(required)_ |
341
+ | `unauthorized(message?, context?)` | `401` | Unauthorized |
342
+ | `paymentRequired(message?, context?)` | `402` | Payment Required |
343
+ | `forbidden(message?, context?)` | `403` | Forbidden |
344
+ | `notFound(message?, context?)` | `404` | Not Found |
345
+ | `methodNotAllowed(message?, context?)` | `405` | Method Not Allowed |
346
+ | `notAcceptable(message?, context?)` | `406` | Not Acceptable |
347
+ | `proxyAuthRequired(message?, context?)` | `407` | Proxy Authentication Required |
348
+ | `requestTimeout(message?, context?)` | `408` | Request Timeout |
349
+ | `conflict(message, context?)` | `409` | _(required)_ |
350
+ | `gone(message?, context?)` | `410` | Gone |
351
+ | `lengthRequired(message?, context?)` | `411` | Length Required |
352
+ | `preconditionFailed(message?, context?)` | `412` | Precondition Failed |
353
+ | `payloadTooLarge(message?, context?)` | `413` | Payload Too Large |
354
+ | `uriTooLong(message?, context?)` | `414` | URI Too Long |
355
+ | `unsupportedMediaType(message?, context?)` | `415` | Unsupported Media Type |
356
+ | `rangeNotSatisfiable(message?, context?)` | `416` | Range Not Satisfiable |
357
+ | `expectationFailed(message?, context?)` | `417` | Expectation Failed |
358
+ | `imATeapot(message?, context?)` | `418` | I'm a Teapot |
359
+ | `misdirectedRequest(message?, context?)` | `421` | Misdirected Request |
360
+ | `unprocessableEntity(message?, context?)` | `422` | Unprocessable Entity |
361
+ | `validationError(message, context?)` | `422` | _(required)_ |
362
+ | `locked(message?, context?)` | `423` | Locked |
363
+ | `failedDependency(message?, context?)` | `424` | Failed Dependency |
364
+ | `tooEarly(message?, context?)` | `425` | Too Early |
365
+ | `upgradeRequired(message?, context?)` | `426` | Upgrade Required |
366
+ | `preconditionRequired(message?, context?)` | `428` | Precondition Required |
367
+ | `tooManyRequests(message?, context?)` | `429` | Too Many Requests |
368
+ | `requestHeaderFieldsTooLarge(message?, context?)` | `431` | Request Header Fields Too Large |
369
+ | `unavailableForLegalReasons(message?, context?)` | `451` | Unavailable For Legal Reasons |
370
+
371
+ </details>
372
+
373
+ <details>
374
+ <summary>๐Ÿ”ด <strong>5xx Server Errors</strong> <em>(click to expand)</em></summary>
375
+
376
+ | Method | Code | Default Message |
377
+ | :-------------------------------------------------- | :---: | :------------------------------ |
378
+ | `internalServerError(message?, context?)` | `500` | Internal Server Error |
379
+ | `notImplemented(message?, context?)` | `501` | Not Implemented |
380
+ | `badGateway(message?, context?)` | `502` | Bad Gateway |
381
+ | `serviceUnavailable(message?, context?)` | `503` | Service Unavailable |
382
+ | `gatewayTimeout(message?, context?)` | `504` | Gateway Timeout |
383
+ | `httpVersionNotSupported(message?, context?)` | `505` | HTTP Version Not Supported |
384
+ | `variantAlsoNegotiates(message?, context?)` | `506` | Variant Also Negotiates |
385
+ | `insufficientStorage(message?, context?)` | `507` | Insufficient Storage |
386
+ | `loopDetected(message?, context?)` | `508` | Loop Detected |
387
+ | `bandwidthLimitExceeded(message?, context?)` | `509` | Bandwidth Limit Exceeded |
388
+ | `notExtended(message?, context?)` | `510` | Not Extended |
389
+ | `networkAuthenticationRequired(message?, context?)` | `511` | Network Authentication Required |
390
+ | `networkConnectTimeout(message?, context?)` | `599` | Network Connect Timeout |
391
+
392
+ </details>
393
+
394
+ ---
395
+
396
+ ## ๐ŸŸฆ TypeScript Support
397
+
398
+ Error Shield ships with **full TypeScript declarations** โ€” zero extra config needed.
241
399
 
242
400
  ```typescript
243
- import { AppError, ErrorCreators, handleError } from "error-shield";
401
+ import {
402
+ AppError,
403
+ Errors,
404
+ handleError,
405
+ asyncHandler,
406
+ expressErrorHandler,
407
+ type ErrorDetails,
408
+ type ErrorHandlerOptions,
409
+ } from "error-shield";
410
+
411
+ // Fully typed error creation
412
+ const error: AppError = Errors.notFound("User not found", {
413
+ userId: 42,
414
+ });
244
415
 
245
- const error: AppError = ErrorCreators.notFound("User not found");
246
- const details = handleError(error);
416
+ // Typed error details
417
+ const details: ErrorDetails = handleError(error, {
418
+ includeStack: true,
419
+ includeTimestamp: true,
420
+ });
247
421
  ```
248
422
 
249
- ## License
423
+ ---
424
+
425
+ ## ๐Ÿค Contributing
426
+
427
+ Contributions, issues, and feature requests are welcome!
428
+
429
+ 1. **Fork** the repository
430
+ 2. **Create** your feature branch โ€” `git checkout -b feature/amazing-feature`
431
+ 3. **Commit** your changes โ€” `git commit -m "feat: add amazing feature"`
432
+ 4. **Push** to the branch โ€” `git push origin feature/amazing-feature`
433
+ 5. **Open** a Pull Request
434
+
435
+ ---
436
+
437
+ ## ๐Ÿ“„ License
438
+
439
+ This project is licensed under the [ISC License](https://opensource.org/licenses/ISC).
440
+
441
+ ---
442
+
443
+ <div align="center">
250
444
 
251
- ISC
445
+ Made with โค๏ธ by **[Gopinath Kathirvel](https://github.com/Gopinathgopi13)**
252
446
 
253
- ## Author
447
+ โญ **If you found this useful, give it a star on [GitHub](https://github.com/Gopinathgopi13/error-shield)!** โญ
254
448
 
255
- Gopinath Kathirvel
449
+ </div>