@naman_deep_singh/errors-utils 1.4.0 → 1.4.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.
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  ```bash
2
2
  @naman_deep_singh/errors-utils
3
3
 
4
- Version: 1.4.0
4
+ Version: 1.4.2
5
5
 
6
6
  A standardized, code-driven error handling system for TypeScript and Express applications, providing consistent error identity, responses, and middleware integration.
7
7
 
@@ -43,22 +43,21 @@ import {
43
43
  NotFoundError,
44
44
  ValidationError,
45
45
  InternalServerError,
46
- ERROR_CODES,
47
46
  } from '@naman_deep_singh/errors-utils'
48
47
 
49
48
  // Basic usage
50
- throw new BadRequestError(ERROR_CODES.BAD_REQUEST)
49
+ throw new BadRequestError()
51
50
 
52
- throw new UnauthorizedError(ERROR_CODES.UNAUTHORIZED)
51
+ throw new UnauthorizedError()
53
52
 
54
- throw new NotFoundError(ERROR_CODES.NOT_FOUND)
53
+ throw new NotFoundError()
55
54
 
56
55
  // With additional details
57
- throw new ValidationError(ERROR_CODES.VALIDATION_FAILED, {
56
+ throw new ValidationError({
58
57
  fields: ['email', 'password'],
59
58
  })
60
59
 
61
- throw new InternalServerError(ERROR_CODES.INTERNAL_SERVER_ERROR)
60
+ throw new InternalServerError()
62
61
 
63
62
  🧾 Error Codes & Messages
64
63
  import {
@@ -87,7 +86,6 @@ import {
87
86
  errorConverter,
88
87
  expressErrorHandler,
89
88
  ValidationError,
90
- ERROR_CODES,
91
89
  } from '@naman_deep_singh/errors-utils'
92
90
 
93
91
  const app = express()
@@ -100,7 +98,9 @@ app.use(expressErrorHandler)
100
98
 
101
99
  app.post('/users', (req, res) => {
102
100
  if (!req.body.email) {
103
- throw new ValidationError(ERROR_CODES.VALIDATION_FAILED)
101
+ throw new ValidationError({
102
+ fields: ['email'],
103
+ })
104
104
  }
105
105
  })
106
106
 
@@ -151,9 +151,15 @@ errorMessageRegistry.register({
151
151
 
152
152
  After this, AppError or any derived class will use the updated messages automatically.
153
153
 
154
- import { AppError } from '@naman_deep_singh/errors-utils'
154
+ import { AppError, ErrorCode } from '@naman_deep_singh/errors-utils'
155
155
 
156
- throw new AppError('CUSTOM_ERROR') // message: "Something went wrong with custom logic"
156
+ throw new AppError(
157
+ 'CUSTOM_ERROR' as ErrorCode,
158
+ 500,
159
+ {
160
+ reason: "Something went wrong with custom logic"
161
+ }
162
+ )
157
163
 
158
164
  📚 Available Error Classes
159
165
  Class Status Code Use Case
@@ -170,6 +176,8 @@ ValidationError 422 Validation errors
170
176
  RateLimitError 429 Rate limiting
171
177
  CryptoIntegrityError 500 Crypto validation failure
172
178
  InternalServerError 500 Server-side failures
179
+ ServiceUnavailableError 500 Service not available
180
+
173
181
  🎯 Standard Error Response
174
182
 
175
183
  All errors resolve to a consistent response shape:
@@ -180,7 +188,7 @@ All errors resolve to a consistent response shape:
180
188
  "message": "Validation failed",
181
189
  "details": {
182
190
  "fields": ["email"]
183
- }
191
+ },
184
192
  }
185
193
 
186
194
  📄 License
@@ -0,0 +1,14 @@
1
+ export * from './AppError';
2
+ export * from './HTTPError';
3
+ export * from './BadRequestError';
4
+ export * from './UnauthorizedError';
5
+ export * from './ForbiddenError';
6
+ export * from './NotFoundError';
7
+ export * from './ConflictError';
8
+ export * from './ValidationError';
9
+ export * from './TooManyRequestsError';
10
+ export * from './TokenExpiredError';
11
+ export * from './TokenMalformedError';
12
+ export * from './InternalServerError';
13
+ export * from './CryptoIntegrityError';
14
+ export * from './ServiceUnavailableError';
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./AppError"), exports);
18
+ __exportStar(require("./HTTPError"), exports);
19
+ // =========================
20
+ // 4xx Client Errors
21
+ // =========================
22
+ __exportStar(require("./BadRequestError"), exports);
23
+ __exportStar(require("./UnauthorizedError"), exports);
24
+ __exportStar(require("./ForbiddenError"), exports);
25
+ __exportStar(require("./NotFoundError"), exports);
26
+ __exportStar(require("./ConflictError"), exports);
27
+ __exportStar(require("./ValidationError"), exports);
28
+ __exportStar(require("./TooManyRequestsError"), exports);
29
+ // =========================
30
+ // Auth / Token Errors
31
+ // =========================
32
+ __exportStar(require("./TokenExpiredError"), exports);
33
+ __exportStar(require("./TokenMalformedError"), exports);
34
+ // =========================
35
+ // 5xx Server Errors
36
+ // =========================
37
+ __exportStar(require("./InternalServerError"), exports);
38
+ __exportStar(require("./CryptoIntegrityError"), exports);
39
+ __exportStar(require("./ServiceUnavailableError"), exports);
@@ -1,16 +1,4 @@
1
1
  export * from './errorRegistry';
2
- export * from './error/AppError';
3
- export * from './error/HTTPError';
4
- export * from './error/BadRequestError';
5
- export * from './error/UnauthorizedError';
6
- export * from './error/ForbiddenError';
7
- export * from './error/NotFoundError';
8
- export * from './error/ConflictError';
9
- export * from './error/ValidationError';
10
- export * from './error/TooManyRequestsError';
11
- export * from './error/TokenExpiredError';
12
- export * from './error/TokenMalformedError';
13
- export * from './error/InternalServerError';
14
- export * from './error/CryptoIntegrityError';
2
+ export * from './error';
15
3
  export * from './constants';
16
4
  export * from './middleware/express';
package/dist/cjs/index.js CHANGED
@@ -16,28 +16,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./errorRegistry"), exports);
18
18
  // =========================
19
- __exportStar(require("./error/AppError"), exports);
20
- __exportStar(require("./error/HTTPError"), exports);
19
+ // default errors
21
20
  // =========================
22
- // 4xx Client Errors
23
- // =========================
24
- __exportStar(require("./error/BadRequestError"), exports);
25
- __exportStar(require("./error/UnauthorizedError"), exports);
26
- __exportStar(require("./error/ForbiddenError"), exports);
27
- __exportStar(require("./error/NotFoundError"), exports);
28
- __exportStar(require("./error/ConflictError"), exports);
29
- __exportStar(require("./error/ValidationError"), exports);
30
- __exportStar(require("./error/TooManyRequestsError"), exports);
31
- // =========================
32
- // Auth / Token Errors
33
- // =========================
34
- __exportStar(require("./error/TokenExpiredError"), exports);
35
- __exportStar(require("./error/TokenMalformedError"), exports);
36
- // =========================
37
- // 5xx Server Errors
38
- // =========================
39
- __exportStar(require("./error/InternalServerError"), exports);
40
- __exportStar(require("./error/CryptoIntegrityError"), exports);
21
+ __exportStar(require("./error"), exports);
41
22
  // =========================
42
23
  // Constants
43
24
  // =========================
@@ -0,0 +1,14 @@
1
+ export * from './AppError';
2
+ export * from './HTTPError';
3
+ export * from './BadRequestError';
4
+ export * from './UnauthorizedError';
5
+ export * from './ForbiddenError';
6
+ export * from './NotFoundError';
7
+ export * from './ConflictError';
8
+ export * from './ValidationError';
9
+ export * from './TooManyRequestsError';
10
+ export * from './TokenExpiredError';
11
+ export * from './TokenMalformedError';
12
+ export * from './InternalServerError';
13
+ export * from './CryptoIntegrityError';
14
+ export * from './ServiceUnavailableError';
@@ -0,0 +1,23 @@
1
+ export * from './AppError';
2
+ export * from './HTTPError';
3
+ // =========================
4
+ // 4xx Client Errors
5
+ // =========================
6
+ export * from './BadRequestError';
7
+ export * from './UnauthorizedError';
8
+ export * from './ForbiddenError';
9
+ export * from './NotFoundError';
10
+ export * from './ConflictError';
11
+ export * from './ValidationError';
12
+ export * from './TooManyRequestsError';
13
+ // =========================
14
+ // Auth / Token Errors
15
+ // =========================
16
+ export * from './TokenExpiredError';
17
+ export * from './TokenMalformedError';
18
+ // =========================
19
+ // 5xx Server Errors
20
+ // =========================
21
+ export * from './InternalServerError';
22
+ export * from './CryptoIntegrityError';
23
+ export * from './ServiceUnavailableError';
@@ -1,16 +1,4 @@
1
1
  export * from './errorRegistry';
2
- export * from './error/AppError';
3
- export * from './error/HTTPError';
4
- export * from './error/BadRequestError';
5
- export * from './error/UnauthorizedError';
6
- export * from './error/ForbiddenError';
7
- export * from './error/NotFoundError';
8
- export * from './error/ConflictError';
9
- export * from './error/ValidationError';
10
- export * from './error/TooManyRequestsError';
11
- export * from './error/TokenExpiredError';
12
- export * from './error/TokenMalformedError';
13
- export * from './error/InternalServerError';
14
- export * from './error/CryptoIntegrityError';
2
+ export * from './error';
15
3
  export * from './constants';
16
4
  export * from './middleware/express';
package/dist/esm/index.js CHANGED
@@ -1,27 +1,8 @@
1
1
  export * from './errorRegistry';
2
2
  // =========================
3
- export * from './error/AppError';
4
- export * from './error/HTTPError';
3
+ // default errors
5
4
  // =========================
6
- // 4xx Client Errors
7
- // =========================
8
- export * from './error/BadRequestError';
9
- export * from './error/UnauthorizedError';
10
- export * from './error/ForbiddenError';
11
- export * from './error/NotFoundError';
12
- export * from './error/ConflictError';
13
- export * from './error/ValidationError';
14
- export * from './error/TooManyRequestsError';
15
- // =========================
16
- // Auth / Token Errors
17
- // =========================
18
- export * from './error/TokenExpiredError';
19
- export * from './error/TokenMalformedError';
20
- // =========================
21
- // 5xx Server Errors
22
- // =========================
23
- export * from './error/InternalServerError';
24
- export * from './error/CryptoIntegrityError';
5
+ export * from './error';
25
6
  // =========================
26
7
  // Constants
27
8
  // =========================
@@ -0,0 +1,14 @@
1
+ export * from './AppError';
2
+ export * from './HTTPError';
3
+ export * from './BadRequestError';
4
+ export * from './UnauthorizedError';
5
+ export * from './ForbiddenError';
6
+ export * from './NotFoundError';
7
+ export * from './ConflictError';
8
+ export * from './ValidationError';
9
+ export * from './TooManyRequestsError';
10
+ export * from './TokenExpiredError';
11
+ export * from './TokenMalformedError';
12
+ export * from './InternalServerError';
13
+ export * from './CryptoIntegrityError';
14
+ export * from './ServiceUnavailableError';
@@ -1,16 +1,4 @@
1
1
  export * from './errorRegistry';
2
- export * from './error/AppError';
3
- export * from './error/HTTPError';
4
- export * from './error/BadRequestError';
5
- export * from './error/UnauthorizedError';
6
- export * from './error/ForbiddenError';
7
- export * from './error/NotFoundError';
8
- export * from './error/ConflictError';
9
- export * from './error/ValidationError';
10
- export * from './error/TooManyRequestsError';
11
- export * from './error/TokenExpiredError';
12
- export * from './error/TokenMalformedError';
13
- export * from './error/InternalServerError';
14
- export * from './error/CryptoIntegrityError';
2
+ export * from './error';
15
3
  export * from './constants';
16
4
  export * from './middleware/express';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naman_deep_singh/errors-utils",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "description": "Standardized error classes and Express middleware for consistent error handling with TypeScript",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",