@naman_deep_singh/errors-utils 1.1.1 → 1.3.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/README.md +157 -82
- package/dist/cjs/constants/errorCodes.d.ts +32 -0
- package/dist/cjs/constants/errorCodes.js +34 -0
- package/dist/cjs/constants/errorMessages.d.ts +2 -0
- package/dist/cjs/constants/errorMessages.js +34 -0
- package/dist/cjs/constants/index.d.ts +2 -0
- package/dist/cjs/constants/index.js +18 -0
- package/dist/cjs/error/AppError.d.ts +10 -1
- package/dist/cjs/error/AppError.js +15 -2
- package/dist/cjs/error/BadRequestError.d.ts +1 -1
- package/dist/cjs/error/BadRequestError.js +4 -2
- package/dist/cjs/error/ConflictError.d.ts +1 -1
- package/dist/cjs/error/ConflictError.js +4 -2
- package/dist/cjs/error/CryptoIntegrityError.d.ts +4 -0
- package/dist/cjs/error/CryptoIntegrityError.js +11 -0
- package/dist/cjs/error/ForbiddenError.d.ts +1 -1
- package/dist/cjs/error/ForbiddenError.js +4 -2
- package/dist/cjs/error/HTTPError.d.ts +3 -2
- package/dist/cjs/error/HTTPError.js +3 -3
- package/dist/cjs/error/InternalServerError.d.ts +2 -1
- package/dist/cjs/error/InternalServerError.js +4 -2
- package/dist/cjs/error/NotFoundError.d.ts +1 -1
- package/dist/cjs/error/NotFoundError.js +4 -2
- package/dist/cjs/error/RateLimitError.d.ts +4 -0
- package/dist/cjs/error/RateLimitError.js +11 -0
- package/dist/cjs/error/TokenExpiredError.d.ts +4 -0
- package/dist/cjs/error/TokenExpiredError.js +12 -0
- package/dist/cjs/error/TokenMalformedError.d.ts +4 -0
- package/dist/cjs/error/TokenMalformedError.js +12 -0
- package/dist/cjs/error/TooManyRequestsError.d.ts +5 -0
- package/dist/cjs/error/TooManyRequestsError.js +12 -0
- package/dist/cjs/error/UnauthorizedError.d.ts +2 -1
- package/dist/cjs/error/UnauthorizedError.js +4 -2
- package/dist/cjs/error/ValidationError.d.ts +1 -1
- package/dist/cjs/error/ValidationError.js +4 -2
- package/dist/cjs/middleware/express/errorConverter.d.ts +1 -1
- package/dist/cjs/middleware/express/errorConverter.js +23 -11
- package/dist/cjs/middleware/express/errorHandler.d.ts +1 -1
- package/dist/cjs/middleware/express/errorHandler.js +7 -6
- package/dist/esm/constants/errorCodes.d.ts +32 -0
- package/dist/esm/constants/errorCodes.js +31 -0
- package/dist/esm/constants/errorMessages.d.ts +2 -0
- package/dist/esm/constants/errorMessages.js +31 -0
- package/dist/esm/constants/index.d.ts +2 -0
- package/dist/esm/constants/index.js +2 -0
- package/dist/esm/error/AppError.d.ts +10 -1
- package/dist/esm/error/AppError.js +15 -2
- package/dist/esm/error/BadRequestError.d.ts +1 -1
- package/dist/esm/error/BadRequestError.js +4 -2
- package/dist/esm/error/ConflictError.d.ts +1 -1
- package/dist/esm/error/ConflictError.js +4 -2
- package/dist/esm/error/CryptoIntegrityError.d.ts +4 -0
- package/dist/esm/error/CryptoIntegrityError.js +7 -0
- package/dist/esm/error/ForbiddenError.d.ts +1 -1
- package/dist/esm/error/ForbiddenError.js +4 -2
- package/dist/esm/error/HTTPError.d.ts +3 -2
- package/dist/esm/error/HTTPError.js +3 -3
- package/dist/esm/error/InternalServerError.d.ts +2 -1
- package/dist/esm/error/InternalServerError.js +4 -2
- package/dist/esm/error/NotFoundError.d.ts +1 -1
- package/dist/esm/error/NotFoundError.js +4 -2
- package/dist/esm/error/RateLimitError.d.ts +4 -0
- package/dist/esm/error/RateLimitError.js +7 -0
- package/dist/esm/error/TokenExpiredError.d.ts +4 -0
- package/dist/esm/error/TokenExpiredError.js +8 -0
- package/dist/esm/error/TokenMalformedError.d.ts +4 -0
- package/dist/esm/error/TokenMalformedError.js +8 -0
- package/dist/esm/error/TooManyRequestsError.d.ts +5 -0
- package/dist/esm/error/TooManyRequestsError.js +8 -0
- package/dist/esm/error/UnauthorizedError.d.ts +2 -1
- package/dist/esm/error/UnauthorizedError.js +4 -2
- package/dist/esm/error/ValidationError.d.ts +1 -1
- package/dist/esm/error/ValidationError.js +4 -2
- package/dist/esm/middleware/express/errorConverter.d.ts +1 -1
- package/dist/esm/middleware/express/errorConverter.js +23 -11
- package/dist/esm/middleware/express/errorHandler.d.ts +1 -1
- package/dist/esm/middleware/express/errorHandler.js +7 -6
- package/dist/types/constants/errorCodes.d.ts +32 -0
- package/dist/types/constants/errorMessages.d.ts +2 -0
- package/dist/types/constants/index.d.ts +2 -0
- package/dist/types/error/AppError.d.ts +10 -1
- package/dist/types/error/BadRequestError.d.ts +1 -1
- package/dist/types/error/ConflictError.d.ts +1 -1
- package/dist/types/error/CryptoIntegrityError.d.ts +4 -0
- package/dist/types/error/ForbiddenError.d.ts +1 -1
- package/dist/types/error/HTTPError.d.ts +3 -2
- package/dist/types/error/InternalServerError.d.ts +2 -1
- package/dist/types/error/NotFoundError.d.ts +1 -1
- package/dist/types/error/RateLimitError.d.ts +4 -0
- package/dist/types/error/TokenExpiredError.d.ts +4 -0
- package/dist/types/error/TokenMalformedError.d.ts +4 -0
- package/dist/types/error/TooManyRequestsError.d.ts +5 -0
- package/dist/types/error/UnauthorizedError.d.ts +2 -1
- package/dist/types/error/ValidationError.d.ts +1 -1
- package/dist/types/middleware/express/errorConverter.d.ts +1 -1
- package/dist/types/middleware/express/errorHandler.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,125 +1,200 @@
|
|
|
1
|
-
|
|
1
|
+
@naman_deep_singh/errors-utils
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Version: 1.3.1
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
A standardized, code-driven error handling system for TypeScript and Express applications, providing consistent error identity, responses, and middleware integration.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
🚀 Features
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
- ✅ **Express Middleware** - Error converter and handler
|
|
11
|
-
- ✅ **Response Integration** - Works with @naman_deep_singh/response-utils
|
|
12
|
-
- ✅ **TypeScript Support** - Full type safety
|
|
13
|
-
- ✅ **Consistent Responses** - Standardized error format across your API
|
|
9
|
+
✅ Structured Error Classes — AppError, HTTPError, ValidationError, etc.
|
|
14
10
|
|
|
15
|
-
|
|
11
|
+
✅ Strongly-Typed Error Codes — Centralized error identity via constants
|
|
16
12
|
|
|
17
|
-
|
|
13
|
+
✅ Centralized Error Messages — One source of truth for user-facing messages
|
|
14
|
+
|
|
15
|
+
✅ Express Middleware — Error converter & global handler
|
|
16
|
+
|
|
17
|
+
✅ Response Integration — Works seamlessly with @naman_deep_singh/response-utils
|
|
18
|
+
|
|
19
|
+
✅ TypeScript First — Full type safety & IntelliSense
|
|
20
|
+
|
|
21
|
+
✅ Consistent API Responses — Unified error shape across services
|
|
22
|
+
|
|
23
|
+
📦 Installation
|
|
18
24
|
npm install @naman_deep_singh/errors-utils
|
|
19
|
-
```
|
|
20
25
|
|
|
21
|
-
|
|
26
|
+
🧠 Design Philosophy
|
|
27
|
+
|
|
28
|
+
This package is code-driven, not message-driven.
|
|
29
|
+
|
|
30
|
+
Errors are identified by stable error codes
|
|
31
|
+
|
|
32
|
+
Messages are resolved internally via centralized mappings
|
|
33
|
+
|
|
34
|
+
API contracts remain stable even if messages change
|
|
35
|
+
|
|
36
|
+
This ensures:
|
|
22
37
|
|
|
23
|
-
|
|
38
|
+
Consistency across microservices
|
|
24
39
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
40
|
+
Safe refactoring
|
|
41
|
+
|
|
42
|
+
Better logging, tracing, and observability
|
|
43
|
+
|
|
44
|
+
🔧 Usage
|
|
45
|
+
Creating Errors (Recommended)
|
|
46
|
+
import {
|
|
47
|
+
BadRequestError,
|
|
48
|
+
UnauthorizedError,
|
|
30
49
|
NotFoundError,
|
|
31
50
|
ValidationError,
|
|
32
|
-
InternalServerError
|
|
33
|
-
|
|
51
|
+
InternalServerError,
|
|
52
|
+
ERROR_CODES,
|
|
53
|
+
} from '@naman_deep_singh/errors-utils'
|
|
54
|
+
|
|
55
|
+
throw new BadRequestError(ERROR_CODES.BAD_REQUEST)
|
|
56
|
+
|
|
57
|
+
throw new UnauthorizedError(ERROR_CODES.UNAUTHORIZED)
|
|
58
|
+
|
|
59
|
+
throw new NotFoundError(ERROR_CODES.NOT_FOUND)
|
|
60
|
+
|
|
61
|
+
throw new ValidationError(ERROR_CODES.VALIDATION_FAILED, {
|
|
62
|
+
fields: ['email', 'password'],
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
throw new InternalServerError(ERROR_CODES.INTERNAL_SERVER_ERROR)
|
|
66
|
+
|
|
67
|
+
🧾 Error Codes & Messages
|
|
68
|
+
|
|
69
|
+
The package exposes a strongly-typed error code system.
|
|
34
70
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
71
|
+
import {
|
|
72
|
+
ERROR_CODES,
|
|
73
|
+
ERROR_MESSAGES,
|
|
74
|
+
ErrorCode,
|
|
75
|
+
} from '@naman_deep_singh/errors-utils'
|
|
40
76
|
|
|
41
|
-
|
|
42
|
-
throw new BadRequestError('Validation failed', {
|
|
43
|
-
fields: ['email', 'password']
|
|
44
|
-
});
|
|
45
|
-
```
|
|
77
|
+
Exports
|
|
46
78
|
|
|
47
|
-
|
|
79
|
+
ERROR_CODES — Canonical list of all supported error codes
|
|
48
80
|
|
|
49
|
-
|
|
50
|
-
import express from 'express';
|
|
51
|
-
import { expressErrorHandler, errorConverter } from '@naman_deep_singh/errors-utils';
|
|
81
|
+
ERROR_MESSAGES — Mapping of error codes → user-facing messages
|
|
52
82
|
|
|
53
|
-
|
|
83
|
+
ErrorCode — Union type of all valid error codes
|
|
54
84
|
|
|
55
|
-
|
|
56
|
-
|
|
85
|
+
Why Error Codes?
|
|
86
|
+
|
|
87
|
+
✅ Consistent error identity across services
|
|
88
|
+
|
|
89
|
+
✅ Centralized message management
|
|
90
|
+
|
|
91
|
+
✅ Safer API contracts
|
|
92
|
+
|
|
93
|
+
✅ Improved logging & observability
|
|
94
|
+
|
|
95
|
+
🌐 Express Middleware
|
|
96
|
+
|
|
97
|
+
This package provides Express-specific middleware under the hood
|
|
98
|
+
and exposes a clean public API.
|
|
99
|
+
|
|
100
|
+
import express from 'express'
|
|
101
|
+
import {
|
|
102
|
+
errorConverter,
|
|
103
|
+
expressErrorHandler,
|
|
104
|
+
ValidationError,
|
|
105
|
+
ERROR_CODES,
|
|
106
|
+
} from '@naman_deep_singh/errors-utils'
|
|
107
|
+
|
|
108
|
+
const app = express()
|
|
109
|
+
|
|
110
|
+
// Convert unknown / third-party errors → AppError
|
|
111
|
+
app.use(errorConverter)
|
|
57
112
|
|
|
58
113
|
// Handle all errors consistently
|
|
59
|
-
app.use(expressErrorHandler)
|
|
114
|
+
app.use(expressErrorHandler)
|
|
60
115
|
|
|
61
|
-
// In your routes
|
|
62
116
|
app.post('/users', (req, res) => {
|
|
63
117
|
if (!req.body.email) {
|
|
64
|
-
throw new
|
|
118
|
+
throw new ValidationError(ERROR_CODES.VALIDATION_FAILED)
|
|
65
119
|
}
|
|
66
|
-
|
|
67
|
-
});
|
|
68
|
-
```
|
|
120
|
+
})
|
|
69
121
|
|
|
70
|
-
|
|
122
|
+
Middleware Responsibilities
|
|
71
123
|
|
|
72
|
-
|
|
124
|
+
errorConverter
|
|
73
125
|
|
|
74
|
-
|
|
75
|
-
import { createServer } from '@naman_deep_singh/server-utils';
|
|
76
|
-
import { expressErrorHandler } from '@naman_deep_singh/errors-utils';
|
|
126
|
+
Converts unknown errors into AppError
|
|
77
127
|
|
|
78
|
-
|
|
128
|
+
Preserves known operational errors
|
|
79
129
|
|
|
80
|
-
|
|
81
|
-
server.app.use(expressErrorHandler);
|
|
82
|
-
```
|
|
130
|
+
expressErrorHandler
|
|
83
131
|
|
|
84
|
-
|
|
132
|
+
Sends standardized API responses
|
|
85
133
|
|
|
86
|
-
|
|
87
|
-
import { responderMiddleware } from '@naman_deep_singh/response-utils';
|
|
134
|
+
Integrates with @naman_deep_singh/response-utils
|
|
88
135
|
|
|
89
|
-
|
|
90
|
-
server.app.use(expressErrorHandler); // Uses response-utils for consistent format
|
|
91
|
-
```
|
|
136
|
+
Hides internal errors in production
|
|
92
137
|
|
|
93
|
-
|
|
138
|
+
🔗 Integration
|
|
139
|
+
With @naman_deep_singh/response-utils
|
|
140
|
+
import { responderMiddleware } from '@naman_deep_singh/response-utils'
|
|
141
|
+
import { expressErrorHandler } from '@naman_deep_singh/errors-utils'
|
|
94
142
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
| `AppError` | Custom | Base error class |
|
|
98
|
-
| `BadRequestError` | 400 | Invalid input data |
|
|
99
|
-
| `UnauthorizedError` | 401 | Authentication failures |
|
|
100
|
-
| `ForbiddenError` | 403 | Authorization failures |
|
|
101
|
-
| `NotFoundError` | 404 | Resource not found |
|
|
102
|
-
| `ConflictError` | 409 | Resource conflicts |
|
|
103
|
-
| `ValidationError` | 422 | Input validation errors |
|
|
104
|
-
| `InternalServerError` | 500 | Server errors |
|
|
143
|
+
app.use(responderMiddleware())
|
|
144
|
+
app.use(expressErrorHandler)
|
|
105
145
|
|
|
106
|
-
|
|
146
|
+
With @naman_deep_singh/server-utils
|
|
147
|
+
import { createServer } from '@naman_deep_singh/server-utils'
|
|
148
|
+
import { expressErrorHandler } from '@naman_deep_singh/errors-utils'
|
|
107
149
|
|
|
108
|
-
|
|
150
|
+
const server = createServer('My API', '1.0.0')
|
|
151
|
+
|
|
152
|
+
server.app.use(expressErrorHandler)
|
|
153
|
+
|
|
154
|
+
🧠 Custom Errors
|
|
155
|
+
|
|
156
|
+
You can safely extend existing errors:
|
|
157
|
+
|
|
158
|
+
import {
|
|
159
|
+
InternalServerError,
|
|
160
|
+
ERROR_CODES,
|
|
161
|
+
} from '@naman_deep_singh/errors-utils'
|
|
162
|
+
|
|
163
|
+
export class CryptoIntegrityError extends InternalServerError {
|
|
164
|
+
constructor(details?: unknown, cause?: Error) {
|
|
165
|
+
super(ERROR_CODES.CRYPTO_INTEGRITY_ERROR, details, cause)
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
📚 Available Error Classes
|
|
170
|
+
Class Status Code Use Case
|
|
171
|
+
AppError Custom Base error class
|
|
172
|
+
HTTPError 4xx / 5xx Base HTTP error
|
|
173
|
+
BadRequestError 400 Invalid input
|
|
174
|
+
UnauthorizedError 401 Authentication failures
|
|
175
|
+
TokenExpiredError 401 Expired tokens
|
|
176
|
+
TokenMalformedError 401 Invalid token format
|
|
177
|
+
ForbiddenError 403 Authorization failures
|
|
178
|
+
NotFoundError 404 Resource not found
|
|
179
|
+
ConflictError 409 Resource conflicts
|
|
180
|
+
ValidationError 422 Validation errors
|
|
181
|
+
RateLimitError 429 Rate limiting
|
|
182
|
+
TooManyRequestsError 429 Alias of RateLimitError
|
|
183
|
+
CryptoIntegrityError 500 Crypto validation failure
|
|
184
|
+
InternalServerError 500 Server-side failures
|
|
185
|
+
🎯 Standard Error Response
|
|
186
|
+
|
|
187
|
+
All errors resolve to a consistent response shape:
|
|
109
188
|
|
|
110
|
-
```json
|
|
111
189
|
{
|
|
112
190
|
"success": false,
|
|
113
|
-
"
|
|
114
|
-
"
|
|
115
|
-
"
|
|
116
|
-
"
|
|
117
|
-
|
|
118
|
-
},
|
|
119
|
-
"meta": null
|
|
191
|
+
"code": "VALIDATION_FAILED",
|
|
192
|
+
"message": "Validation failed",
|
|
193
|
+
"details": {
|
|
194
|
+
"fields": ["email"]
|
|
195
|
+
}
|
|
120
196
|
}
|
|
121
|
-
```
|
|
122
197
|
|
|
123
|
-
|
|
198
|
+
📄 License
|
|
124
199
|
|
|
125
200
|
ISC © Naman Deep Singh
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export declare const ERROR_CODES: {
|
|
2
|
+
readonly BAD_REQUEST: "BAD_REQUEST";
|
|
3
|
+
readonly UNAUTHORIZED: "UNAUTHORIZED";
|
|
4
|
+
readonly FORBIDDEN: "FORBIDDEN";
|
|
5
|
+
readonly NOT_FOUND: "NOT_FOUND";
|
|
6
|
+
readonly CONFLICT: "CONFLICT";
|
|
7
|
+
readonly VALIDATION_FAILED: "VALIDATION_FAILED";
|
|
8
|
+
readonly RATE_LIMIT_EXCEEDED: "RATE_LIMIT_EXCEEDED";
|
|
9
|
+
readonly INTERNAL_SERVER_ERROR: "INTERNAL_SERVER_ERROR";
|
|
10
|
+
readonly CRYPTO_INTEGRITY_ERROR: "CRYPTO_INTEGRITY_ERROR";
|
|
11
|
+
readonly TOO_MANY_REQUESTS: "TOO_MANY_REQUESTS";
|
|
12
|
+
readonly TOKEN_EXPIRED: "TOKEN_EXPIRED";
|
|
13
|
+
readonly TOKEN_INVALID: "TOKEN_INVALID";
|
|
14
|
+
readonly TOKEN_NOT_PROVIDED: "TOKEN_NOT_PROVIDED";
|
|
15
|
+
readonly TOKEN_NOT_FOUND: "TOKEN_NOT_FOUND";
|
|
16
|
+
readonly TOKEN_NOT_CREATED: "TOKEN_NOT_CREATED";
|
|
17
|
+
readonly TOKEN_NOT_UPDATED: "TOKEN_NOT_UPDATED";
|
|
18
|
+
readonly TOKEN_NOT_DELETED: "TOKEN_NOT_DELETED";
|
|
19
|
+
readonly TOKEN_NOT_VALIDATED: "TOKEN_NOT_VALIDATED";
|
|
20
|
+
readonly TOKEN_NOT_REFRESHED: "TOKEN_NOT_REFRESHED";
|
|
21
|
+
readonly TOKEN_NOT_REVOKED: "TOKEN_NOT_REVOKED";
|
|
22
|
+
readonly TOKEN_NOT_BLACKLISTED: "TOKEN_NOT_BLACKLISTED";
|
|
23
|
+
readonly TOKEN_NOT_WHITELISTED: "TOKEN_NOT_WHITELISTED";
|
|
24
|
+
readonly TOKEN_NOT_DECODED: "TOKEN_NOT_DECODED";
|
|
25
|
+
readonly TOKEN_NOT_ENCODED: "TOKEN_NOT_ENCODED";
|
|
26
|
+
readonly TOKEN_NOT_SIGNED: "TOKEN_NOT_SIGNED";
|
|
27
|
+
readonly TOKEN_NOT_VERIFIED: "TOKEN_NOT_VERIFIED";
|
|
28
|
+
readonly TOKEN_NOT_DECRYPTED: "TOKEN_NOT_DECRYPTED";
|
|
29
|
+
readonly TOKEN_NOT_ENCRYPTED: "TOKEN_NOT_ENCRYPTED";
|
|
30
|
+
readonly TOKEN_NOT_GENERATED: "TOKEN_NOT_GENERATED";
|
|
31
|
+
};
|
|
32
|
+
export type ErrorCode = keyof typeof ERROR_CODES;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ERROR_CODES = void 0;
|
|
4
|
+
exports.ERROR_CODES = {
|
|
5
|
+
BAD_REQUEST: 'BAD_REQUEST',
|
|
6
|
+
UNAUTHORIZED: 'UNAUTHORIZED',
|
|
7
|
+
FORBIDDEN: 'FORBIDDEN',
|
|
8
|
+
NOT_FOUND: 'NOT_FOUND',
|
|
9
|
+
CONFLICT: 'CONFLICT',
|
|
10
|
+
VALIDATION_FAILED: 'VALIDATION_FAILED',
|
|
11
|
+
RATE_LIMIT_EXCEEDED: 'RATE_LIMIT_EXCEEDED',
|
|
12
|
+
INTERNAL_SERVER_ERROR: 'INTERNAL_SERVER_ERROR',
|
|
13
|
+
CRYPTO_INTEGRITY_ERROR: 'CRYPTO_INTEGRITY_ERROR',
|
|
14
|
+
TOO_MANY_REQUESTS: 'TOO_MANY_REQUESTS',
|
|
15
|
+
TOKEN_EXPIRED: 'TOKEN_EXPIRED',
|
|
16
|
+
TOKEN_INVALID: 'TOKEN_INVALID',
|
|
17
|
+
TOKEN_NOT_PROVIDED: 'TOKEN_NOT_PROVIDED',
|
|
18
|
+
TOKEN_NOT_FOUND: 'TOKEN_NOT_FOUND',
|
|
19
|
+
TOKEN_NOT_CREATED: 'TOKEN_NOT_CREATED',
|
|
20
|
+
TOKEN_NOT_UPDATED: 'TOKEN_NOT_UPDATED',
|
|
21
|
+
TOKEN_NOT_DELETED: 'TOKEN_NOT_DELETED',
|
|
22
|
+
TOKEN_NOT_VALIDATED: 'TOKEN_NOT_VALIDATED',
|
|
23
|
+
TOKEN_NOT_REFRESHED: 'TOKEN_NOT_REFRESHED',
|
|
24
|
+
TOKEN_NOT_REVOKED: 'TOKEN_NOT_REVOKED',
|
|
25
|
+
TOKEN_NOT_BLACKLISTED: 'TOKEN_NOT_BLACKLISTED',
|
|
26
|
+
TOKEN_NOT_WHITELISTED: 'TOKEN_NOT_WHITELISTED',
|
|
27
|
+
TOKEN_NOT_DECODED: 'TOKEN_NOT_DECODED',
|
|
28
|
+
TOKEN_NOT_ENCODED: 'TOKEN_NOT_ENCODED',
|
|
29
|
+
TOKEN_NOT_SIGNED: 'TOKEN_NOT_SIGNED',
|
|
30
|
+
TOKEN_NOT_VERIFIED: 'TOKEN_NOT_VERIFIED',
|
|
31
|
+
TOKEN_NOT_DECRYPTED: 'TOKEN_NOT_DECRYPTED',
|
|
32
|
+
TOKEN_NOT_ENCRYPTED: 'TOKEN_NOT_ENCRYPTED',
|
|
33
|
+
TOKEN_NOT_GENERATED: 'TOKEN_NOT_GENERATED',
|
|
34
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ERROR_MESSAGES = void 0;
|
|
4
|
+
exports.ERROR_MESSAGES = {
|
|
5
|
+
BAD_REQUEST: 'Bad request',
|
|
6
|
+
UNAUTHORIZED: 'Unauthorized',
|
|
7
|
+
FORBIDDEN: 'Forbidden',
|
|
8
|
+
NOT_FOUND: 'Resource not found',
|
|
9
|
+
CONFLICT: 'Conflict occurred',
|
|
10
|
+
VALIDATION_FAILED: 'Validation failed',
|
|
11
|
+
RATE_LIMIT_EXCEEDED: 'Too many requests',
|
|
12
|
+
INTERNAL_SERVER_ERROR: 'Internal server error',
|
|
13
|
+
CRYPTO_INTEGRITY_ERROR: 'Crypto integrity error',
|
|
14
|
+
TOO_MANY_REQUESTS: 'Too many requests',
|
|
15
|
+
TOKEN_EXPIRED: 'Token expired',
|
|
16
|
+
TOKEN_INVALID: 'Invalid token',
|
|
17
|
+
TOKEN_NOT_PROVIDED: 'Token not provided',
|
|
18
|
+
TOKEN_NOT_FOUND: 'Token not found',
|
|
19
|
+
TOKEN_NOT_CREATED: 'Token not created',
|
|
20
|
+
TOKEN_NOT_UPDATED: 'Token not updated',
|
|
21
|
+
TOKEN_NOT_DELETED: 'Token not deleted',
|
|
22
|
+
TOKEN_NOT_VALIDATED: 'Token not validated',
|
|
23
|
+
TOKEN_NOT_REFRESHED: 'Token not refreshed',
|
|
24
|
+
TOKEN_NOT_REVOKED: 'Token not revoked',
|
|
25
|
+
TOKEN_NOT_BLACKLISTED: 'Token not blacklisted',
|
|
26
|
+
TOKEN_NOT_WHITELISTED: 'Token not whitelisted',
|
|
27
|
+
TOKEN_NOT_DECODED: 'Token not decoded',
|
|
28
|
+
TOKEN_NOT_ENCODED: 'Token not encoded',
|
|
29
|
+
TOKEN_NOT_SIGNED: 'Token not signed',
|
|
30
|
+
TOKEN_NOT_VERIFIED: 'Token not verified',
|
|
31
|
+
TOKEN_NOT_DECRYPTED: 'Token not decrypted',
|
|
32
|
+
TOKEN_NOT_ENCRYPTED: 'Token not encrypted',
|
|
33
|
+
TOKEN_NOT_GENERATED: 'Token not generated',
|
|
34
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
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("./errorCodes"), exports);
|
|
18
|
+
__exportStar(require("./errorMessages"), exports);
|
|
@@ -1,6 +1,15 @@
|
|
|
1
|
+
import { type ErrorCode } from '../constants';
|
|
1
2
|
export declare class AppError extends Error {
|
|
2
3
|
statusCode: number;
|
|
3
4
|
isOperational: boolean;
|
|
5
|
+
code: ErrorCode;
|
|
4
6
|
details?: unknown;
|
|
5
|
-
|
|
7
|
+
cause?: Error;
|
|
8
|
+
constructor(code: ErrorCode, statusCode?: number, details?: unknown, cause?: Error);
|
|
9
|
+
toJSON(): {
|
|
10
|
+
success: boolean;
|
|
11
|
+
code: "BAD_REQUEST" | "UNAUTHORIZED" | "FORBIDDEN" | "NOT_FOUND" | "CONFLICT" | "VALIDATION_FAILED" | "RATE_LIMIT_EXCEEDED" | "INTERNAL_SERVER_ERROR" | "CRYPTO_INTEGRITY_ERROR" | "TOO_MANY_REQUESTS" | "TOKEN_EXPIRED" | "TOKEN_INVALID" | "TOKEN_NOT_PROVIDED" | "TOKEN_NOT_FOUND" | "TOKEN_NOT_CREATED" | "TOKEN_NOT_UPDATED" | "TOKEN_NOT_DELETED" | "TOKEN_NOT_VALIDATED" | "TOKEN_NOT_REFRESHED" | "TOKEN_NOT_REVOKED" | "TOKEN_NOT_BLACKLISTED" | "TOKEN_NOT_WHITELISTED" | "TOKEN_NOT_DECODED" | "TOKEN_NOT_ENCODED" | "TOKEN_NOT_SIGNED" | "TOKEN_NOT_VERIFIED" | "TOKEN_NOT_DECRYPTED" | "TOKEN_NOT_ENCRYPTED" | "TOKEN_NOT_GENERATED";
|
|
12
|
+
message: string;
|
|
13
|
+
details: {} | null;
|
|
14
|
+
};
|
|
6
15
|
}
|
|
@@ -1,13 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AppError = void 0;
|
|
4
|
+
const response_utils_1 = require("@naman_deep_singh/response-utils");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
4
6
|
class AppError extends Error {
|
|
5
|
-
constructor(
|
|
6
|
-
super(
|
|
7
|
+
constructor(code, statusCode = response_utils_1.HTTP_STATUS.SERVER_ERROR.INTERNAL_SERVER_ERROR, details, cause) {
|
|
8
|
+
super(constants_1.ERROR_MESSAGES[code]); // message comes from mapping
|
|
9
|
+
this.code = code;
|
|
7
10
|
this.statusCode = statusCode;
|
|
8
11
|
this.isOperational = true;
|
|
9
12
|
this.details = details;
|
|
13
|
+
if (cause)
|
|
14
|
+
this.cause = cause;
|
|
10
15
|
Error.captureStackTrace(this, this.constructor);
|
|
11
16
|
}
|
|
17
|
+
toJSON() {
|
|
18
|
+
return {
|
|
19
|
+
success: false,
|
|
20
|
+
code: this.code,
|
|
21
|
+
message: this.message,
|
|
22
|
+
details: this.details ?? null,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
12
25
|
}
|
|
13
26
|
exports.AppError = AppError;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BadRequestError = void 0;
|
|
4
|
+
const response_utils_1 = require("@naman_deep_singh/response-utils");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
4
6
|
const HTTPError_1 = require("./HTTPError");
|
|
5
7
|
class BadRequestError extends HTTPError_1.HTTPError {
|
|
6
|
-
constructor(
|
|
7
|
-
super(
|
|
8
|
+
constructor(details, cause) {
|
|
9
|
+
super(constants_1.ERROR_CODES.BAD_REQUEST, response_utils_1.HTTP_STATUS.CLIENT_ERROR.BAD_REQUEST, details, cause);
|
|
8
10
|
}
|
|
9
11
|
}
|
|
10
12
|
exports.BadRequestError = BadRequestError;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ConflictError = void 0;
|
|
4
|
+
const response_utils_1 = require("@naman_deep_singh/response-utils");
|
|
5
|
+
const constants_1 = require("src/constants");
|
|
4
6
|
const HTTPError_1 = require("./HTTPError");
|
|
5
7
|
class ConflictError extends HTTPError_1.HTTPError {
|
|
6
|
-
constructor(
|
|
7
|
-
super(
|
|
8
|
+
constructor(details, cause) {
|
|
9
|
+
super(constants_1.ERROR_CODES.CONFLICT, response_utils_1.HTTP_STATUS.CLIENT_ERROR.CONFLICT, details, cause);
|
|
8
10
|
}
|
|
9
11
|
}
|
|
10
12
|
exports.ConflictError = ConflictError;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CryptoIntegrityError = void 0;
|
|
4
|
+
const constants_1 = require("src/constants");
|
|
5
|
+
const InternalServerError_1 = require("./InternalServerError");
|
|
6
|
+
class CryptoIntegrityError extends InternalServerError_1.InternalServerError {
|
|
7
|
+
constructor(details, cause) {
|
|
8
|
+
super(constants_1.ERROR_CODES.CRYPTO_INTEGRITY_ERROR, details, cause);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.CryptoIntegrityError = CryptoIntegrityError;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ForbiddenError = void 0;
|
|
4
|
+
const response_utils_1 = require("@naman_deep_singh/response-utils");
|
|
5
|
+
const constants_1 = require("src/constants");
|
|
4
6
|
const HTTPError_1 = require("./HTTPError");
|
|
5
7
|
class ForbiddenError extends HTTPError_1.HTTPError {
|
|
6
|
-
constructor(
|
|
7
|
-
super(
|
|
8
|
+
constructor(details, cause) {
|
|
9
|
+
super(constants_1.ERROR_CODES.FORBIDDEN, response_utils_1.HTTP_STATUS.CLIENT_ERROR.FORBIDDEN, details, cause);
|
|
8
10
|
}
|
|
9
11
|
}
|
|
10
12
|
exports.ForbiddenError = ForbiddenError;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { ErrorCode } from '../constants';
|
|
1
2
|
import { AppError } from './AppError';
|
|
2
3
|
export declare class HTTPError extends AppError {
|
|
3
|
-
status:
|
|
4
|
-
constructor(
|
|
4
|
+
status: 'fail' | 'error';
|
|
5
|
+
constructor(errorCode: ErrorCode, statusCode: number, details?: unknown, cause?: Error);
|
|
5
6
|
}
|
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.HTTPError = void 0;
|
|
4
4
|
const AppError_1 = require("./AppError");
|
|
5
5
|
class HTTPError extends AppError_1.AppError {
|
|
6
|
-
constructor(
|
|
7
|
-
super(
|
|
8
|
-
this.status =
|
|
6
|
+
constructor(errorCode, statusCode, details, cause) {
|
|
7
|
+
super(errorCode, statusCode, details, cause);
|
|
8
|
+
this.status = statusCode >= 400 && statusCode < 500 ? 'fail' : 'error';
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
exports.HTTPError = HTTPError;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import { type ErrorCode } from 'src/constants';
|
|
1
2
|
import { HTTPError } from './HTTPError';
|
|
2
3
|
export declare class InternalServerError extends HTTPError {
|
|
3
|
-
constructor(
|
|
4
|
+
constructor(errorCode?: ErrorCode, details?: unknown, cause?: Error);
|
|
4
5
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InternalServerError = void 0;
|
|
4
|
+
const response_utils_1 = require("@naman_deep_singh/response-utils");
|
|
5
|
+
const constants_1 = require("src/constants");
|
|
4
6
|
const HTTPError_1 = require("./HTTPError");
|
|
5
7
|
class InternalServerError extends HTTPError_1.HTTPError {
|
|
6
|
-
constructor(
|
|
7
|
-
super(
|
|
8
|
+
constructor(errorCode = constants_1.ERROR_CODES.INTERNAL_SERVER_ERROR, details, cause) {
|
|
9
|
+
super(errorCode, response_utils_1.HTTP_STATUS.SERVER_ERROR.INTERNAL_SERVER_ERROR, details, cause);
|
|
8
10
|
}
|
|
9
11
|
}
|
|
10
12
|
exports.InternalServerError = InternalServerError;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NotFoundError = void 0;
|
|
4
|
+
const response_utils_1 = require("@naman_deep_singh/response-utils");
|
|
5
|
+
const constants_1 = require("src/constants");
|
|
4
6
|
const HTTPError_1 = require("./HTTPError");
|
|
5
7
|
class NotFoundError extends HTTPError_1.HTTPError {
|
|
6
|
-
constructor(
|
|
7
|
-
super(
|
|
8
|
+
constructor(details, cause) {
|
|
9
|
+
super(constants_1.ERROR_CODES.NOT_FOUND, response_utils_1.HTTP_STATUS.CLIENT_ERROR.NOT_FOUND, details, cause);
|
|
8
10
|
}
|
|
9
11
|
}
|
|
10
12
|
exports.NotFoundError = NotFoundError;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RateLimitError = void 0;
|
|
4
|
+
const constants_1 = require("src/constants");
|
|
5
|
+
const TooManyRequestsError_1 = require("./TooManyRequestsError");
|
|
6
|
+
class RateLimitError extends TooManyRequestsError_1.TooManyRequestsError {
|
|
7
|
+
constructor(details, cause) {
|
|
8
|
+
super(constants_1.ERROR_CODES.RATE_LIMIT_EXCEEDED, details, cause);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.RateLimitError = RateLimitError;
|