error-shield 1.2.0 → 1.2.2

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 (2) hide show
  1. package/README.md +22 -26
  2. package/package.json +3 -3
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 `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 |
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
- ErrorCreators,
57
+ Errors,
58
58
  expressErrorHandler,
59
59
  asyncHandler,
60
60
  } = require("error-shield");
61
61
 
62
62
  // 1️⃣ Throw meaningful errors
63
- throw ErrorCreators.notFound("User not found", { userId: 42 });
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 { ErrorCreators } = require("error-shield");
144
+ const { Errors } = require("error-shield");
145
145
 
146
146
  // 🔴 400 — Bad Request
147
- throw ErrorCreators.badRequest("Invalid input provided", { field: "email" });
147
+ throw Errors.badRequest("Invalid input provided", { field: "email" });
148
148
 
149
149
  // 🔒 401 — Unauthorized
150
- throw ErrorCreators.unauthorized("Authentication required");
150
+ throw Errors.unauthorized("Authentication required");
151
151
 
152
152
  // 🔍 404 — Not Found
153
- throw ErrorCreators.notFound("User not found", { userId: 123 });
153
+ throw Errors.notFound("User not found", { userId: 123 });
154
154
 
155
155
  // ✏️ 422 — Validation Error
156
- throw ErrorCreators.validationError("Email is required", { field: "email" });
156
+ throw Errors.validationError("Email is required", { field: "email" });
157
157
 
158
158
  // 🚦 429 — Too Many Requests
159
- throw ErrorCreators.tooManyRequests("Rate limit exceeded", { retryAfter: 60 });
159
+ throw Errors.tooManyRequests("Rate limit exceeded", { retryAfter: 60 });
160
160
 
161
161
  // 💥 500 — Internal Server Error
162
- throw ErrorCreators.internalServerError("Unexpected failure");
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 ErrorCreators.notFound("User not found", { userId: req.params.id });
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
- ErrorCreators.methodName(message?, context?)
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
- ErrorCreators,
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 = ErrorCreators.notFound("User not found", {
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "error-shield",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
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",
@@ -35,8 +35,8 @@
35
35
  },
36
36
  "author": "Gopinath Kathirvel",
37
37
  "license": "ISC",
38
- "main": "index.js",
39
- "types": "index.d.ts",
38
+ "main": "dist/index.js",
39
+ "types": "dist/index.d.ts",
40
40
  "engines": {
41
41
  "node": ">=14.0.0"
42
42
  }