@naman_deep_singh/errors-utils 1.4.1 โ†’ 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.
Files changed (2) hide show
  1. package/README.md +20 -12
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  ```bash
2
2
  @naman_deep_singh/errors-utils
3
3
 
4
- Version: 1.4.1
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naman_deep_singh/errors-utils",
3
- "version": "1.4.1",
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",