@catbee/utils 0.0.8-rc.1 → 0.0.8-rc.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/build/esm/config.d.ts +0 -1
- package/build/esm/config.js +6 -7
- package/build/esm/index.d.ts +0 -1
- package/build/esm/index.js +0 -1
- package/build/esm/servers/server.builder.d.ts +0 -1
- package/build/esm/servers/server.builder.js +99 -147
- package/build/esm/servers/server.d.ts +0 -1
- package/build/esm/servers/server.js +591 -876
- package/build/esm/types/api-response.d.ts +0 -1
- package/build/esm/types/api-response.js +0 -1
- package/build/esm/types/index.d.ts +0 -1
- package/build/esm/types/index.js +0 -1
- package/build/esm/types/server.d.ts +0 -1
- package/build/esm/types/server.js +0 -1
- package/build/esm/utils/array.utils.d.ts +0 -1
- package/build/esm/utils/array.utils.js +48 -86
- package/build/esm/utils/async.utils.d.ts +0 -1
- package/build/esm/utils/async.utils.js +247 -524
- package/build/esm/utils/cache.utils.d.ts +0 -1
- package/build/esm/utils/cache.utils.js +96 -301
- package/build/esm/utils/context-store.utils.d.ts +0 -1
- package/build/esm/utils/context-store.utils.js +62 -79
- package/build/esm/utils/crypto.utils.d.ts +0 -1
- package/build/esm/utils/crypto.utils.js +78 -175
- package/build/esm/utils/date.utils.d.ts +0 -1
- package/build/esm/utils/date.utils.js +47 -53
- package/build/esm/utils/decorators.utils.d.ts +30 -27
- package/build/esm/utils/decorators.utils.js +417 -461
- package/build/esm/utils/dir.utils.d.ts +0 -1
- package/build/esm/utils/dir.utils.js +264 -786
- package/build/esm/utils/env.utils.d.ts +0 -1
- package/build/esm/utils/env.utils.js +180 -271
- package/build/esm/utils/exception.utils.d.ts +0 -1
- package/build/esm/utils/exception.utils.js +112 -289
- package/build/esm/utils/fs.utils.d.ts +0 -1
- package/build/esm/utils/fs.utils.js +169 -401
- package/build/esm/utils/http-status-codes.d.ts +0 -1
- package/build/esm/utils/http-status-codes.js +0 -1
- package/build/esm/utils/id.utils.d.ts +0 -1
- package/build/esm/utils/id.utils.js +5 -9
- package/build/esm/utils/logger.utils.d.ts +0 -1
- package/build/esm/utils/logger.utils.js +34 -71
- package/build/esm/utils/middleware.utils.d.ts +0 -1
- package/build/esm/utils/middleware.utils.js +65 -155
- package/build/esm/utils/obj.utils.d.ts +0 -1
- package/build/esm/utils/obj.utils.js +69 -176
- package/build/esm/utils/performance.utils.d.ts +0 -1
- package/build/esm/utils/performance.utils.js +92 -195
- package/build/esm/utils/request.utils.d.ts +0 -1
- package/build/esm/utils/request.utils.js +41 -74
- package/build/esm/utils/response.utils.d.ts +0 -1
- package/build/esm/utils/response.utils.js +84 -107
- package/build/esm/utils/stream.utils.d.ts +0 -1
- package/build/esm/utils/stream.utils.js +38 -113
- package/build/esm/utils/string.utils.d.ts +0 -1
- package/build/esm/utils/string.utils.js +6 -11
- package/build/esm/utils/type.utils.d.ts +0 -1
- package/build/esm/utils/type.utils.js +8 -12
- package/build/esm/utils/url.utils.d.ts +0 -1
- package/build/esm/utils/url.utils.js +49 -127
- package/build/esm/utils/validate.utils.d.ts +0 -1
- package/build/esm/utils/validate.utils.js +23 -40
- package/package.json +3 -33
- package/build/esm/config.js.map +0 -1
- package/build/esm/index.js.map +0 -1
- package/build/esm/servers/server.builder.js.map +0 -1
- package/build/esm/servers/server.js.map +0 -1
- package/build/esm/types/api-response.js.map +0 -1
- package/build/esm/types/index.js.map +0 -1
- package/build/esm/types/server.js.map +0 -1
- package/build/esm/utils/array.utils.js.map +0 -1
- package/build/esm/utils/async.utils.js.map +0 -1
- package/build/esm/utils/cache.utils.js.map +0 -1
- package/build/esm/utils/context-store.utils.js.map +0 -1
- package/build/esm/utils/crypto.utils.js.map +0 -1
- package/build/esm/utils/date.utils.js.map +0 -1
- package/build/esm/utils/decorators.utils.js.map +0 -1
- package/build/esm/utils/dir.utils.js.map +0 -1
- package/build/esm/utils/env.utils.js.map +0 -1
- package/build/esm/utils/exception.utils.js.map +0 -1
- package/build/esm/utils/fs.utils.js.map +0 -1
- package/build/esm/utils/http-status-codes.js.map +0 -1
- package/build/esm/utils/id.utils.js.map +0 -1
- package/build/esm/utils/logger.utils.js.map +0 -1
- package/build/esm/utils/middleware.utils.js.map +0 -1
- package/build/esm/utils/obj.utils.js.map +0 -1
- package/build/esm/utils/performance.utils.js.map +0 -1
- package/build/esm/utils/request.utils.js.map +0 -1
- package/build/esm/utils/response.utils.js.map +0 -1
- package/build/esm/utils/stream.utils.js.map +0 -1
- package/build/esm/utils/string.utils.js.map +0 -1
- package/build/esm/utils/type.utils.js.map +0 -1
- package/build/esm/utils/url.utils.js.map +0 -1
- package/build/esm/utils/validate.utils.js.map +0 -1
- package/build/esnext/config.d.ts +0 -122
- package/build/esnext/config.js +0 -133
- package/build/esnext/config.js.map +0 -1
- package/build/esnext/index.d.ts +0 -27
- package/build/esnext/index.js +0 -50
- package/build/esnext/index.js.map +0 -1
- package/build/esnext/servers/server.builder.d.ts +0 -508
- package/build/esnext/servers/server.builder.js +0 -657
- package/build/esnext/servers/server.builder.js.map +0 -1
- package/build/esnext/servers/server.d.ts +0 -256
- package/build/esnext/servers/server.js +0 -955
- package/build/esnext/servers/server.js.map +0 -1
- package/build/esnext/types/api-response.d.ts +0 -152
- package/build/esnext/types/api-response.js +0 -34
- package/build/esnext/types/api-response.js.map +0 -1
- package/build/esnext/types/index.d.ts +0 -125
- package/build/esnext/types/index.js +0 -25
- package/build/esnext/types/index.js.map +0 -1
- package/build/esnext/types/server.d.ts +0 -268
- package/build/esnext/types/server.js +0 -25
- package/build/esnext/types/server.js.map +0 -1
- package/build/esnext/utils/array.utils.d.ts +0 -168
- package/build/esnext/utils/array.utils.js +0 -345
- package/build/esnext/utils/array.utils.js.map +0 -1
- package/build/esnext/utils/async.utils.d.ts +0 -265
- package/build/esnext/utils/async.utils.js +0 -620
- package/build/esnext/utils/async.utils.js.map +0 -1
- package/build/esnext/utils/cache.utils.d.ts +0 -153
- package/build/esnext/utils/cache.utils.js +0 -293
- package/build/esnext/utils/cache.utils.js.map +0 -1
- package/build/esnext/utils/context-store.utils.d.ts +0 -189
- package/build/esnext/utils/context-store.utils.js +0 -289
- package/build/esnext/utils/context-store.utils.js.map +0 -1
- package/build/esnext/utils/crypto.utils.d.ts +0 -160
- package/build/esnext/utils/crypto.utils.js +0 -276
- package/build/esnext/utils/crypto.utils.js.map +0 -1
- package/build/esnext/utils/date.utils.d.ts +0 -159
- package/build/esnext/utils/date.utils.js +0 -384
- package/build/esnext/utils/date.utils.js.map +0 -1
- package/build/esnext/utils/decorators.utils.d.ts +0 -508
- package/build/esnext/utils/decorators.utils.js +0 -877
- package/build/esnext/utils/decorators.utils.js.map +0 -1
- package/build/esnext/utils/dir.utils.d.ts +0 -196
- package/build/esnext/utils/dir.utils.js +0 -477
- package/build/esnext/utils/dir.utils.js.map +0 -1
- package/build/esnext/utils/env.utils.d.ts +0 -377
- package/build/esnext/utils/env.utils.js +0 -785
- package/build/esnext/utils/env.utils.js.map +0 -1
- package/build/esnext/utils/exception.utils.d.ts +0 -230
- package/build/esnext/utils/exception.utils.js +0 -381
- package/build/esnext/utils/exception.utils.js.map +0 -1
- package/build/esnext/utils/fs.utils.d.ts +0 -164
- package/build/esnext/utils/fs.utils.js +0 -349
- package/build/esnext/utils/fs.utils.js.map +0 -1
- package/build/esnext/utils/http-status-codes.d.ts +0 -266
- package/build/esnext/utils/http-status-codes.js +0 -295
- package/build/esnext/utils/http-status-codes.js.map +0 -1
- package/build/esnext/utils/id.utils.d.ts +0 -36
- package/build/esnext/utils/id.utils.js +0 -84
- package/build/esnext/utils/id.utils.js.map +0 -1
- package/build/esnext/utils/logger.utils.d.ts +0 -160
- package/build/esnext/utils/logger.utils.js +0 -300
- package/build/esnext/utils/logger.utils.js.map +0 -1
- package/build/esnext/utils/middleware.utils.d.ts +0 -100
- package/build/esnext/utils/middleware.utils.js +0 -236
- package/build/esnext/utils/middleware.utils.js.map +0 -1
- package/build/esnext/utils/obj.utils.d.ts +0 -124
- package/build/esnext/utils/obj.utils.js +0 -413
- package/build/esnext/utils/obj.utils.js.map +0 -1
- package/build/esnext/utils/performance.utils.d.ts +0 -136
- package/build/esnext/utils/performance.utils.js +0 -271
- package/build/esnext/utils/performance.utils.js.map +0 -1
- package/build/esnext/utils/request.utils.d.ts +0 -86
- package/build/esnext/utils/request.utils.js +0 -186
- package/build/esnext/utils/request.utils.js.map +0 -1
- package/build/esnext/utils/response.utils.d.ts +0 -163
- package/build/esnext/utils/response.utils.js +0 -247
- package/build/esnext/utils/response.utils.js.map +0 -1
- package/build/esnext/utils/stream.utils.d.ts +0 -88
- package/build/esnext/utils/stream.utils.js +0 -210
- package/build/esnext/utils/stream.utils.js.map +0 -1
- package/build/esnext/utils/string.utils.d.ts +0 -93
- package/build/esnext/utils/string.utils.js +0 -165
- package/build/esnext/utils/string.utils.js.map +0 -1
- package/build/esnext/utils/type.utils.d.ts +0 -90
- package/build/esnext/utils/type.utils.js +0 -187
- package/build/esnext/utils/type.utils.js.map +0 -1
- package/build/esnext/utils/url.utils.d.ts +0 -141
- package/build/esnext/utils/url.utils.js +0 -304
- package/build/esnext/utils/url.utils.js.map +0 -1
- package/build/esnext/utils/validate.utils.d.ts +0 -177
- package/build/esnext/utils/validate.utils.js +0 -320
- package/build/esnext/utils/validate.utils.js.map +0 -1
- package/build/src/config.d.ts +0 -122
- package/build/src/config.js +0 -138
- package/build/src/config.js.map +0 -1
- package/build/src/index.d.ts +0 -27
- package/build/src/index.js +0 -69
- package/build/src/index.js.map +0 -1
- package/build/src/servers/server.builder.d.ts +0 -508
- package/build/src/servers/server.builder.js +0 -661
- package/build/src/servers/server.builder.js.map +0 -1
- package/build/src/servers/server.d.ts +0 -256
- package/build/src/servers/server.js +0 -962
- package/build/src/servers/server.js.map +0 -1
- package/build/src/types/api-response.d.ts +0 -152
- package/build/src/types/api-response.js +0 -37
- package/build/src/types/api-response.js.map +0 -1
- package/build/src/types/index.d.ts +0 -125
- package/build/src/types/index.js +0 -26
- package/build/src/types/index.js.map +0 -1
- package/build/src/types/server.d.ts +0 -268
- package/build/src/types/server.js +0 -26
- package/build/src/types/server.js.map +0 -1
- package/build/src/utils/array.utils.d.ts +0 -168
- package/build/src/utils/array.utils.js +0 -364
- package/build/src/utils/array.utils.js.map +0 -1
- package/build/src/utils/async.utils.d.ts +0 -265
- package/build/src/utils/async.utils.js +0 -641
- package/build/src/utils/async.utils.js.map +0 -1
- package/build/src/utils/cache.utils.d.ts +0 -153
- package/build/src/utils/cache.utils.js +0 -297
- package/build/src/utils/cache.utils.js.map +0 -1
- package/build/src/utils/context-store.utils.d.ts +0 -189
- package/build/src/utils/context-store.utils.js +0 -296
- package/build/src/utils/context-store.utils.js.map +0 -1
- package/build/src/utils/crypto.utils.d.ts +0 -160
- package/build/src/utils/crypto.utils.js +0 -293
- package/build/src/utils/crypto.utils.js.map +0 -1
- package/build/src/utils/date.utils.d.ts +0 -159
- package/build/src/utils/date.utils.js +0 -396
- package/build/src/utils/date.utils.js.map +0 -1
- package/build/src/utils/decorators.utils.d.ts +0 -508
- package/build/src/utils/decorators.utils.js +0 -896
- package/build/src/utils/decorators.utils.js.map +0 -1
- package/build/src/utils/dir.utils.d.ts +0 -196
- package/build/src/utils/dir.utils.js +0 -501
- package/build/src/utils/dir.utils.js.map +0 -1
- package/build/src/utils/env.utils.d.ts +0 -377
- package/build/src/utils/env.utils.js +0 -789
- package/build/src/utils/env.utils.js.map +0 -1
- package/build/src/utils/exception.utils.d.ts +0 -230
- package/build/src/utils/exception.utils.js +0 -407
- package/build/src/utils/exception.utils.js.map +0 -1
- package/build/src/utils/fs.utils.d.ts +0 -164
- package/build/src/utils/fs.utils.js +0 -372
- package/build/src/utils/fs.utils.js.map +0 -1
- package/build/src/utils/http-status-codes.d.ts +0 -266
- package/build/src/utils/http-status-codes.js +0 -298
- package/build/src/utils/http-status-codes.js.map +0 -1
- package/build/src/utils/id.utils.d.ts +0 -36
- package/build/src/utils/id.utils.js +0 -91
- package/build/src/utils/id.utils.js.map +0 -1
- package/build/src/utils/logger.utils.d.ts +0 -160
- package/build/src/utils/logger.utils.js +0 -346
- package/build/src/utils/logger.utils.js.map +0 -1
- package/build/src/utils/middleware.utils.d.ts +0 -100
- package/build/src/utils/middleware.utils.js +0 -244
- package/build/src/utils/middleware.utils.js.map +0 -1
- package/build/src/utils/obj.utils.d.ts +0 -124
- package/build/src/utils/obj.utils.js +0 -429
- package/build/src/utils/obj.utils.js.map +0 -1
- package/build/src/utils/performance.utils.d.ts +0 -136
- package/build/src/utils/performance.utils.js +0 -278
- package/build/src/utils/performance.utils.js.map +0 -1
- package/build/src/utils/request.utils.d.ts +0 -86
- package/build/src/utils/request.utils.js +0 -195
- package/build/src/utils/request.utils.js.map +0 -1
- package/build/src/utils/response.utils.d.ts +0 -163
- package/build/src/utils/response.utils.js +0 -260
- package/build/src/utils/response.utils.js.map +0 -1
- package/build/src/utils/stream.utils.d.ts +0 -88
- package/build/src/utils/stream.utils.js +0 -218
- package/build/src/utils/stream.utils.js.map +0 -1
- package/build/src/utils/string.utils.d.ts +0 -93
- package/build/src/utils/string.utils.js +0 -179
- package/build/src/utils/string.utils.js.map +0 -1
- package/build/src/utils/type.utils.d.ts +0 -90
- package/build/src/utils/type.utils.js +0 -196
- package/build/src/utils/type.utils.js.map +0 -1
- package/build/src/utils/url.utils.d.ts +0 -141
- package/build/src/utils/url.utils.js +0 -317
- package/build/src/utils/url.utils.js.map +0 -1
- package/build/src/utils/validate.utils.d.ts +0 -177
- package/build/src/utils/validate.utils.js +0 -345
- package/build/src/utils/validate.utils.js.map +0 -1
|
@@ -1,381 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* The MIT License
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2025 Catbee Technologies. https://catbee-utils.npm.hprasath.com/license
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
import { HttpStatusCodes } from './http-status-codes';
|
|
25
|
-
import { getLogger } from './logger.utils';
|
|
26
|
-
import { ErrorResponse } from './response.utils';
|
|
27
|
-
/**
|
|
28
|
-
* Generic HTTP error class used for custom exceptions with any status code.
|
|
29
|
-
* Inherit this when you need to throw errors dynamically at runtime.
|
|
30
|
-
*/
|
|
31
|
-
export class HttpError extends ErrorResponse {
|
|
32
|
-
/**
|
|
33
|
-
* Creates a new HTTP error instance.
|
|
34
|
-
* @param status - A valid HTTP status code (e.g., 400, 500).
|
|
35
|
-
* @param message - The error message to return to the client.
|
|
36
|
-
*/
|
|
37
|
-
constructor(status, message) {
|
|
38
|
-
super(message);
|
|
39
|
-
this.status = status;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Represents a 500 Internal Server Error.
|
|
44
|
-
* Use this for unexpected backend errors that are not caused by the client.
|
|
45
|
-
*/
|
|
46
|
-
export class InternalServerErrorException extends ErrorResponse {
|
|
47
|
-
/**
|
|
48
|
-
* @param message - Optional custom message. Defaults to "Internal server error".
|
|
49
|
-
*/
|
|
50
|
-
constructor(message = 'Internal server error') {
|
|
51
|
-
super(message);
|
|
52
|
-
this.status = HttpStatusCodes.INTERNAL_SERVER_ERROR;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Represents a 401 Unauthorized Error.
|
|
57
|
-
* Indicates that authentication is required and has failed or not been provided.
|
|
58
|
-
*/
|
|
59
|
-
export class UnauthorizedException extends ErrorResponse {
|
|
60
|
-
/**
|
|
61
|
-
* @param message - Optional custom message. Defaults to "Unauthorized".
|
|
62
|
-
*/
|
|
63
|
-
constructor(message = 'Unauthorized') {
|
|
64
|
-
super(message);
|
|
65
|
-
this.status = HttpStatusCodes.UNAUTHORIZED;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Represents a 400 Bad Request Error.
|
|
70
|
-
* Indicates that the client has sent invalid data (e.g., malformed request body).
|
|
71
|
-
*/
|
|
72
|
-
export class BadRequestException extends ErrorResponse {
|
|
73
|
-
/**
|
|
74
|
-
* @param message - Optional custom message. Defaults to "Bad request".
|
|
75
|
-
*/
|
|
76
|
-
constructor(message = 'Bad request') {
|
|
77
|
-
super(message);
|
|
78
|
-
this.status = HttpStatusCodes.BAD_REQUEST;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Represents a 404 Not Found Error.
|
|
83
|
-
* Used when a requested resource (e.g., user, file) could not be located.
|
|
84
|
-
*/
|
|
85
|
-
export class NotFoundException extends ErrorResponse {
|
|
86
|
-
/**
|
|
87
|
-
* @param message - Optional custom message. Defaults to "Resource not found".
|
|
88
|
-
*/
|
|
89
|
-
constructor(message = 'Resource not found') {
|
|
90
|
-
super(message);
|
|
91
|
-
this.status = HttpStatusCodes.NOT_FOUND;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Represents a 403 Forbidden Error.
|
|
96
|
-
* Indicates that the client is authenticated but not allowed to access the resource.
|
|
97
|
-
*/
|
|
98
|
-
export class ForbiddenException extends ErrorResponse {
|
|
99
|
-
/**
|
|
100
|
-
* @param message - Optional custom message. Defaults to "Forbidden".
|
|
101
|
-
*/
|
|
102
|
-
constructor(message = 'Forbidden') {
|
|
103
|
-
super(message);
|
|
104
|
-
this.status = HttpStatusCodes.FORBIDDEN;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Represents a 409 Conflict Error.
|
|
109
|
-
* Commonly used when a resource already exists or a versioning conflict occurs.
|
|
110
|
-
*/
|
|
111
|
-
export class ConflictException extends ErrorResponse {
|
|
112
|
-
/**
|
|
113
|
-
* @param message - Optional custom message. Defaults to "Conflict".
|
|
114
|
-
*/
|
|
115
|
-
constructor(message = 'Conflict') {
|
|
116
|
-
super(message);
|
|
117
|
-
this.status = HttpStatusCodes.CONFLICT;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Represents a 502 Bad Gateway Error.
|
|
122
|
-
* Used when the server receives an invalid response from an upstream server.
|
|
123
|
-
*/
|
|
124
|
-
export class BadGatewayException extends ErrorResponse {
|
|
125
|
-
/**
|
|
126
|
-
* @param message - Optional custom message. Defaults to "Bad Gateway".
|
|
127
|
-
*/
|
|
128
|
-
constructor(message = 'Bad Gateway') {
|
|
129
|
-
super(message);
|
|
130
|
-
this.status = HttpStatusCodes.BAD_GATEWAY;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Represents a 429 Too Many Requests Error.
|
|
135
|
-
* Returned when the client has hit a rate limit.
|
|
136
|
-
*/
|
|
137
|
-
export class TooManyRequestsException extends ErrorResponse {
|
|
138
|
-
/**
|
|
139
|
-
* @param message - Optional custom message. Defaults to "Too many requests".
|
|
140
|
-
*/
|
|
141
|
-
constructor(message = 'Too many requests') {
|
|
142
|
-
super(message);
|
|
143
|
-
this.status = HttpStatusCodes.TOO_MANY_REQUESTS;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Represents a 503 Service Unavailable Error.
|
|
148
|
-
* Indicates that the server is temporarily unavailable (e.g., for maintenance).
|
|
149
|
-
*/
|
|
150
|
-
export class ServiceUnavailableException extends ErrorResponse {
|
|
151
|
-
/**
|
|
152
|
-
* @param message - Optional custom message. Defaults to "Service Unavailable".
|
|
153
|
-
*/
|
|
154
|
-
constructor(message = 'Service Unavailable') {
|
|
155
|
-
super(message);
|
|
156
|
-
this.status = HttpStatusCodes.SERVICE_UNAVAILABLE;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Represents a 504 Gateway Timeout Error.
|
|
161
|
-
* Returned when the server acting as a gateway times out waiting for a response.
|
|
162
|
-
*/
|
|
163
|
-
export class GatewayTimeoutException extends ErrorResponse {
|
|
164
|
-
/**
|
|
165
|
-
* @param message - Optional custom message. Defaults to "Gateway Timeout".
|
|
166
|
-
*/
|
|
167
|
-
constructor(message = 'Gateway Timeout') {
|
|
168
|
-
super(message);
|
|
169
|
-
this.status = HttpStatusCodes.GATEWAY_TIMEOUT;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Represents a 422 Unprocessable Entity Error.
|
|
174
|
-
* Used when the server understands the content type but cannot process the contained instructions.
|
|
175
|
-
*/
|
|
176
|
-
export class UnprocessableEntityException extends ErrorResponse {
|
|
177
|
-
/**
|
|
178
|
-
* @param message - Optional custom message. Defaults to "Unprocessable Entity".
|
|
179
|
-
* @param details - Optional validation details or additional error context.
|
|
180
|
-
*/
|
|
181
|
-
constructor(message = 'Unprocessable Entity', details) {
|
|
182
|
-
super(message);
|
|
183
|
-
this.details = details;
|
|
184
|
-
this.status = HttpStatusCodes.UNPROCESSABLE_ENTITY;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Represents a 405 Method Not Allowed Error.
|
|
189
|
-
* Used when the request method is not supported for the requested resource.
|
|
190
|
-
*/
|
|
191
|
-
export class MethodNotAllowedException extends ErrorResponse {
|
|
192
|
-
/**
|
|
193
|
-
* @param message - Optional custom message. Defaults to "Method Not Allowed".
|
|
194
|
-
* @param allowedMethods - Optional array of allowed HTTP methods.
|
|
195
|
-
*/
|
|
196
|
-
constructor(message = 'Method Not Allowed', allowedMethods) {
|
|
197
|
-
super(message);
|
|
198
|
-
this.allowedMethods = allowedMethods;
|
|
199
|
-
this.status = HttpStatusCodes.METHOD_NOT_ALLOWED;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Represents a 406 Not Acceptable Error.
|
|
204
|
-
* Used when the server cannot produce a response matching the client's accepted content types.
|
|
205
|
-
*/
|
|
206
|
-
export class NotAcceptableException extends ErrorResponse {
|
|
207
|
-
/**
|
|
208
|
-
* @param message - Optional custom message. Defaults to "Not Acceptable".
|
|
209
|
-
*/
|
|
210
|
-
constructor(message = 'Not Acceptable') {
|
|
211
|
-
super(message);
|
|
212
|
-
this.status = HttpStatusCodes.NOT_ACCEPTABLE;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* Represents a 408 Request Timeout Error.
|
|
217
|
-
* Used when the server times out waiting for the client to send a request.
|
|
218
|
-
*/
|
|
219
|
-
export class RequestTimeoutException extends ErrorResponse {
|
|
220
|
-
/**
|
|
221
|
-
* @param message - Optional custom message. Defaults to "Request Timeout".
|
|
222
|
-
*/
|
|
223
|
-
constructor(message = 'Request Timeout') {
|
|
224
|
-
super(message);
|
|
225
|
-
this.status = HttpStatusCodes.REQUEST_TIMEOUT;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* Represents a 415 Unsupported Media Type Error.
|
|
230
|
-
* Used when the request's Content-Type is not supported.
|
|
231
|
-
*/
|
|
232
|
-
export class UnsupportedMediaTypeException extends ErrorResponse {
|
|
233
|
-
/**
|
|
234
|
-
* @param message - Optional custom message. Defaults to "Unsupported Media Type".
|
|
235
|
-
*/
|
|
236
|
-
constructor(message = 'Unsupported Media Type') {
|
|
237
|
-
super(message);
|
|
238
|
-
this.status = HttpStatusCodes.UNSUPPORTED_MEDIA_TYPE;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* Represents a 413 Payload Too Large Error.
|
|
243
|
-
* Used when the request body exceeds server limits.
|
|
244
|
-
*/
|
|
245
|
-
export class PayloadTooLargeException extends ErrorResponse {
|
|
246
|
-
/**
|
|
247
|
-
* @param message - Optional custom message. Defaults to "Payload Too Large".
|
|
248
|
-
*/
|
|
249
|
-
constructor(message = 'Payload Too Large') {
|
|
250
|
-
super(message);
|
|
251
|
-
this.status = HttpStatusCodes.PAYLOAD_TOO_LARGE;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
/**
|
|
255
|
-
* Represents a 507 Insufficient Storage Error.
|
|
256
|
-
* Used when the server has insufficient storage to complete the request.
|
|
257
|
-
*/
|
|
258
|
-
export class InsufficientStorageException extends ErrorResponse {
|
|
259
|
-
/**
|
|
260
|
-
* @param message - Optional custom message. Defaults to "Insufficient Storage".
|
|
261
|
-
*/
|
|
262
|
-
constructor(message = 'Insufficient Storage') {
|
|
263
|
-
super(message);
|
|
264
|
-
this.status = HttpStatusCodes.INSUFFICIENT_STORAGE;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
/**
|
|
268
|
-
* Checks if an error is an instance of HttpError or its subclasses.
|
|
269
|
-
*
|
|
270
|
-
* @param error - The error to check.
|
|
271
|
-
* @returns True if the error is an HttpError, false otherwise.
|
|
272
|
-
*/
|
|
273
|
-
export function isHttpError(error) {
|
|
274
|
-
return error instanceof ErrorResponse;
|
|
275
|
-
}
|
|
276
|
-
/**
|
|
277
|
-
* Creates an HTTP error with the specified status code and message.
|
|
278
|
-
* Factory function for creating appropriate HTTP error instances.
|
|
279
|
-
*
|
|
280
|
-
* @param status - HTTP status code.
|
|
281
|
-
* @param message - Optional custom error message.
|
|
282
|
-
* @returns An instance of the appropriate HTTP error class.
|
|
283
|
-
*/
|
|
284
|
-
export function createHttpError(status, message) {
|
|
285
|
-
switch (status) {
|
|
286
|
-
case HttpStatusCodes.BAD_REQUEST:
|
|
287
|
-
return new BadRequestException(message);
|
|
288
|
-
case HttpStatusCodes.UNAUTHORIZED:
|
|
289
|
-
return new UnauthorizedException(message);
|
|
290
|
-
case HttpStatusCodes.FORBIDDEN:
|
|
291
|
-
return new ForbiddenException(message);
|
|
292
|
-
case HttpStatusCodes.NOT_FOUND:
|
|
293
|
-
return new NotFoundException(message);
|
|
294
|
-
case HttpStatusCodes.METHOD_NOT_ALLOWED:
|
|
295
|
-
return new MethodNotAllowedException(message);
|
|
296
|
-
case HttpStatusCodes.NOT_ACCEPTABLE:
|
|
297
|
-
return new NotAcceptableException(message);
|
|
298
|
-
case HttpStatusCodes.REQUEST_TIMEOUT:
|
|
299
|
-
return new RequestTimeoutException(message);
|
|
300
|
-
case HttpStatusCodes.CONFLICT:
|
|
301
|
-
return new ConflictException(message);
|
|
302
|
-
case HttpStatusCodes.GONE:
|
|
303
|
-
return new HttpError(HttpStatusCodes.GONE, message || 'Gone');
|
|
304
|
-
case HttpStatusCodes.PAYLOAD_TOO_LARGE:
|
|
305
|
-
return new PayloadTooLargeException(message);
|
|
306
|
-
case HttpStatusCodes.UNSUPPORTED_MEDIA_TYPE:
|
|
307
|
-
return new UnsupportedMediaTypeException(message);
|
|
308
|
-
case HttpStatusCodes.UNPROCESSABLE_ENTITY:
|
|
309
|
-
return new UnprocessableEntityException(message);
|
|
310
|
-
case HttpStatusCodes.TOO_MANY_REQUESTS:
|
|
311
|
-
return new TooManyRequestsException(message);
|
|
312
|
-
case HttpStatusCodes.INTERNAL_SERVER_ERROR:
|
|
313
|
-
return new InternalServerErrorException(message);
|
|
314
|
-
case HttpStatusCodes.BAD_GATEWAY:
|
|
315
|
-
return new BadGatewayException(message);
|
|
316
|
-
case HttpStatusCodes.SERVICE_UNAVAILABLE:
|
|
317
|
-
return new ServiceUnavailableException(message);
|
|
318
|
-
case HttpStatusCodes.GATEWAY_TIMEOUT:
|
|
319
|
-
return new GatewayTimeoutException(message);
|
|
320
|
-
case HttpStatusCodes.INSUFFICIENT_STORAGE:
|
|
321
|
-
return new InsufficientStorageException(message);
|
|
322
|
-
default:
|
|
323
|
-
return new HttpError(status, message || `HTTP Error ${status}`);
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
/**
|
|
327
|
-
* Type guard to check if an object has specific error properties.
|
|
328
|
-
*
|
|
329
|
-
* @param error - The object to check.
|
|
330
|
-
* @returns True if object has error-like structure.
|
|
331
|
-
*/
|
|
332
|
-
export function hasErrorShape(error) {
|
|
333
|
-
return (typeof error === 'object' && error !== null && 'message' in error && typeof error.message === 'string');
|
|
334
|
-
}
|
|
335
|
-
/**
|
|
336
|
-
* Safely extracts message from any error type.
|
|
337
|
-
*
|
|
338
|
-
* @param error - Any error object or value.
|
|
339
|
-
* @returns A string error message.
|
|
340
|
-
*/
|
|
341
|
-
export function getErrorMessage(error) {
|
|
342
|
-
if (typeof error === 'string') {
|
|
343
|
-
return error;
|
|
344
|
-
}
|
|
345
|
-
if (error instanceof Error) {
|
|
346
|
-
return error.message;
|
|
347
|
-
}
|
|
348
|
-
if (hasErrorShape(error)) {
|
|
349
|
-
return error.message;
|
|
350
|
-
}
|
|
351
|
-
return 'Unknown error occurred';
|
|
352
|
-
}
|
|
353
|
-
/**
|
|
354
|
-
* Wraps a function and transforms any errors into HTTP errors.
|
|
355
|
-
* Useful for API handlers to ensure consistent error responses.
|
|
356
|
-
*
|
|
357
|
-
* @param handler - The async function to wrap.
|
|
358
|
-
* @returns A function that always returns or throws an HTTP error.
|
|
359
|
-
*/
|
|
360
|
-
export function withErrorHandling(handler) {
|
|
361
|
-
return async (...args) => {
|
|
362
|
-
try {
|
|
363
|
-
return await handler(...args);
|
|
364
|
-
}
|
|
365
|
-
catch (err) {
|
|
366
|
-
if (isHttpError(err)) {
|
|
367
|
-
throw err;
|
|
368
|
-
}
|
|
369
|
-
// Log the original error (consider using a proper logger)
|
|
370
|
-
getLogger().error({ err }, 'Caught error in handler');
|
|
371
|
-
// Extract status code if it exists, otherwise use 500
|
|
372
|
-
let status = HttpStatusCodes.INTERNAL_SERVER_ERROR;
|
|
373
|
-
if (hasErrorShape(err) && typeof err.status === 'number') {
|
|
374
|
-
status = err.status;
|
|
375
|
-
}
|
|
376
|
-
// Create appropriate HTTP error
|
|
377
|
-
throw createHttpError(status, getErrorMessage(err));
|
|
378
|
-
}
|
|
379
|
-
};
|
|
380
|
-
}
|
|
381
|
-
//# sourceMappingURL=exception.utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"exception.utils.js","sourceRoot":"","sources":["../../../src/utils/exception.utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD;;;GAGG;AACH,MAAM,OAAO,SAAU,SAAQ,aAAa;IAC1C;;;;OAIG;IACH,YAAY,MAAc,EAAE,OAAe;QACzC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,4BAA6B,SAAQ,aAAa;IAC7D;;OAEG;IACH,YAAY,UAAkB,uBAAuB;QACnD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,MAAM,GAAG,eAAe,CAA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AC,qBAAqB,CAAC;YACnD,IAAI,aAAa,CAAC,GAAG,CAAC,IAAI,OAAO,GAAG,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;gBACzD,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;YACtB,CAAC;YAED,gCAAgC;YAChC,MAAM,eAAe,CAAC,MAAM,EAAE,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC;QACtD,CAAC;IACH,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/*\n * The MIT License\n *\n * Copyright (c) 2025 Catbee Technologies. https://catbee-utils.npm.hprasath.com/license\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { HttpStatusCodes } from './http-status-codes';\nimport { getLogger } from './logger.utils';\nimport { ErrorResponse } from './response.utils';\n\n/**\n * Generic HTTP error class used for custom exceptions with any status code.\n * Inherit this when you need to throw errors dynamically at runtime.\n */\nexport class HttpError extends ErrorResponse {\n /**\n * Creates a new HTTP error instance.\n * @param status - A valid HTTP status code (e.g., 400, 500).\n * @param message - The error message to return to the client.\n */\n constructor(status: number, message: string) {\n super(message);\n this.status = status;\n }\n}\n\n/**\n * Represents a 500 Internal Server Error.\n * Use this for unexpected backend errors that are not caused by the client.\n */\nexport class InternalServerErrorException extends ErrorResponse {\n /**\n * @param message - Optional custom message. Defaults to \"Internal server error\".\n */\n constructor(message: string = 'Internal server error') {\n super(message);\n this.status = HttpStatusCodes.INTERNAL_SERVER_ERROR;\n }\n}\n\n/**\n * Represents a 401 Unauthorized Error.\n * Indicates that authentication is required and has failed or not been provided.\n */\nexport class UnauthorizedException extends ErrorResponse {\n /**\n * @param message - Optional custom message. Defaults to \"Unauthorized\".\n */\n constructor(message: string = 'Unauthorized') {\n super(message);\n this.status = HttpStatusCodes.UNAUTHORIZED;\n }\n}\n\n/**\n * Represents a 400 Bad Request Error.\n * Indicates that the client has sent invalid data (e.g., malformed request body).\n */\nexport class BadRequestException extends ErrorResponse {\n /**\n * @param message - Optional custom message. Defaults to \"Bad request\".\n */\n constructor(message: string = 'Bad request') {\n super(message);\n this.status = HttpStatusCodes.BAD_REQUEST;\n }\n}\n\n/**\n * Represents a 404 Not Found Error.\n * Used when a requested resource (e.g., user, file) could not be located.\n */\nexport class NotFoundException extends ErrorResponse {\n /**\n * @param message - Optional custom message. Defaults to \"Resource not found\".\n */\n constructor(message: string = 'Resource not found') {\n super(message);\n this.status = HttpStatusCodes.NOT_FOUND;\n }\n}\n\n/**\n * Represents a 403 Forbidden Error.\n * Indicates that the client is authenticated but not allowed to access the resource.\n */\nexport class ForbiddenException extends ErrorResponse {\n /**\n * @param message - Optional custom message. Defaults to \"Forbidden\".\n */\n constructor(message: string = 'Forbidden') {\n super(message);\n this.status = HttpStatusCodes.FORBIDDEN;\n }\n}\n\n/**\n * Represents a 409 Conflict Error.\n * Commonly used when a resource already exists or a versioning conflict occurs.\n */\nexport class ConflictException extends ErrorResponse {\n /**\n * @param message - Optional custom message. Defaults to \"Conflict\".\n */\n constructor(message: string = 'Conflict') {\n super(message);\n this.status = HttpStatusCodes.CONFLICT;\n }\n}\n\n/**\n * Represents a 502 Bad Gateway Error.\n * Used when the server receives an invalid response from an upstream server.\n */\nexport class BadGatewayException extends ErrorResponse {\n /**\n * @param message - Optional custom message. Defaults to \"Bad Gateway\".\n */\n constructor(message: string = 'Bad Gateway') {\n super(message);\n this.status = HttpStatusCodes.BAD_GATEWAY;\n }\n}\n\n/**\n * Represents a 429 Too Many Requests Error.\n * Returned when the client has hit a rate limit.\n */\nexport class TooManyRequestsException extends ErrorResponse {\n /**\n * @param message - Optional custom message. Defaults to \"Too many requests\".\n */\n constructor(message: string = 'Too many requests') {\n super(message);\n this.status = HttpStatusCodes.TOO_MANY_REQUESTS;\n }\n}\n\n/**\n * Represents a 503 Service Unavailable Error.\n * Indicates that the server is temporarily unavailable (e.g., for maintenance).\n */\nexport class ServiceUnavailableException extends ErrorResponse {\n /**\n * @param message - Optional custom message. Defaults to \"Service Unavailable\".\n */\n constructor(message: string = 'Service Unavailable') {\n super(message);\n this.status = HttpStatusCodes.SERVICE_UNAVAILABLE;\n }\n}\n\n/**\n * Represents a 504 Gateway Timeout Error.\n * Returned when the server acting as a gateway times out waiting for a response.\n */\nexport class GatewayTimeoutException extends ErrorResponse {\n /**\n * @param message - Optional custom message. Defaults to \"Gateway Timeout\".\n */\n constructor(message: string = 'Gateway Timeout') {\n super(message);\n this.status = HttpStatusCodes.GATEWAY_TIMEOUT;\n }\n}\n\n/**\n * Represents a 422 Unprocessable Entity Error.\n * Used when the server understands the content type but cannot process the contained instructions.\n */\nexport class UnprocessableEntityException extends ErrorResponse {\n /**\n * @param message - Optional custom message. Defaults to \"Unprocessable Entity\".\n * @param details - Optional validation details or additional error context.\n */\n constructor(\n message: string = 'Unprocessable Entity',\n public details?: Record<string, any>\n ) {\n super(message);\n this.status = HttpStatusCodes.UNPROCESSABLE_ENTITY;\n }\n}\n\n/**\n * Represents a 405 Method Not Allowed Error.\n * Used when the request method is not supported for the requested resource.\n */\nexport class MethodNotAllowedException extends ErrorResponse {\n /**\n * @param message - Optional custom message. Defaults to \"Method Not Allowed\".\n * @param allowedMethods - Optional array of allowed HTTP methods.\n */\n constructor(\n message: string = 'Method Not Allowed',\n public allowedMethods?: string[]\n ) {\n super(message);\n this.status = HttpStatusCodes.METHOD_NOT_ALLOWED;\n }\n}\n\n/**\n * Represents a 406 Not Acceptable Error.\n * Used when the server cannot produce a response matching the client's accepted content types.\n */\nexport class NotAcceptableException extends ErrorResponse {\n /**\n * @param message - Optional custom message. Defaults to \"Not Acceptable\".\n */\n constructor(message: string = 'Not Acceptable') {\n super(message);\n this.status = HttpStatusCodes.NOT_ACCEPTABLE;\n }\n}\n\n/**\n * Represents a 408 Request Timeout Error.\n * Used when the server times out waiting for the client to send a request.\n */\nexport class RequestTimeoutException extends ErrorResponse {\n /**\n * @param message - Optional custom message. Defaults to \"Request Timeout\".\n */\n constructor(message: string = 'Request Timeout') {\n super(message);\n this.status = HttpStatusCodes.REQUEST_TIMEOUT;\n }\n}\n\n/**\n * Represents a 415 Unsupported Media Type Error.\n * Used when the request's Content-Type is not supported.\n */\nexport class UnsupportedMediaTypeException extends ErrorResponse {\n /**\n * @param message - Optional custom message. Defaults to \"Unsupported Media Type\".\n */\n constructor(message: string = 'Unsupported Media Type') {\n super(message);\n this.status = HttpStatusCodes.UNSUPPORTED_MEDIA_TYPE;\n }\n}\n\n/**\n * Represents a 413 Payload Too Large Error.\n * Used when the request body exceeds server limits.\n */\nexport class PayloadTooLargeException extends ErrorResponse {\n /**\n * @param message - Optional custom message. Defaults to \"Payload Too Large\".\n */\n constructor(message: string = 'Payload Too Large') {\n super(message);\n this.status = HttpStatusCodes.PAYLOAD_TOO_LARGE;\n }\n}\n\n/**\n * Represents a 507 Insufficient Storage Error.\n * Used when the server has insufficient storage to complete the request.\n */\nexport class InsufficientStorageException extends ErrorResponse {\n /**\n * @param message - Optional custom message. Defaults to \"Insufficient Storage\".\n */\n constructor(message: string = 'Insufficient Storage') {\n super(message);\n this.status = HttpStatusCodes.INSUFFICIENT_STORAGE;\n }\n}\n\n/**\n * Checks if an error is an instance of HttpError or its subclasses.\n *\n * @param error - The error to check.\n * @returns True if the error is an HttpError, false otherwise.\n */\nexport function isHttpError(error: unknown): error is ErrorResponse {\n return error instanceof ErrorResponse;\n}\n\n/**\n * Creates an HTTP error with the specified status code and message.\n * Factory function for creating appropriate HTTP error instances.\n *\n * @param status - HTTP status code.\n * @param message - Optional custom error message.\n * @returns An instance of the appropriate HTTP error class.\n */\nexport function createHttpError(status: number, message?: string): ErrorResponse {\n switch (status) {\n case HttpStatusCodes.BAD_REQUEST:\n return new BadRequestException(message);\n case HttpStatusCodes.UNAUTHORIZED:\n return new UnauthorizedException(message);\n case HttpStatusCodes.FORBIDDEN:\n return new ForbiddenException(message);\n case HttpStatusCodes.NOT_FOUND:\n return new NotFoundException(message);\n case HttpStatusCodes.METHOD_NOT_ALLOWED:\n return new MethodNotAllowedException(message);\n case HttpStatusCodes.NOT_ACCEPTABLE:\n return new NotAcceptableException(message);\n case HttpStatusCodes.REQUEST_TIMEOUT:\n return new RequestTimeoutException(message);\n case HttpStatusCodes.CONFLICT:\n return new ConflictException(message);\n case HttpStatusCodes.GONE:\n return new HttpError(HttpStatusCodes.GONE, message || 'Gone');\n case HttpStatusCodes.PAYLOAD_TOO_LARGE:\n return new PayloadTooLargeException(message);\n case HttpStatusCodes.UNSUPPORTED_MEDIA_TYPE:\n return new UnsupportedMediaTypeException(message);\n case HttpStatusCodes.UNPROCESSABLE_ENTITY:\n return new UnprocessableEntityException(message);\n case HttpStatusCodes.TOO_MANY_REQUESTS:\n return new TooManyRequestsException(message);\n case HttpStatusCodes.INTERNAL_SERVER_ERROR:\n return new InternalServerErrorException(message);\n case HttpStatusCodes.BAD_GATEWAY:\n return new BadGatewayException(message);\n case HttpStatusCodes.SERVICE_UNAVAILABLE:\n return new ServiceUnavailableException(message);\n case HttpStatusCodes.GATEWAY_TIMEOUT:\n return new GatewayTimeoutException(message);\n case HttpStatusCodes.INSUFFICIENT_STORAGE:\n return new InsufficientStorageException(message);\n default:\n return new HttpError(status, message || `HTTP Error ${status}`);\n }\n}\n\n/**\n * Type guard to check if an object has specific error properties.\n *\n * @param error - The object to check.\n * @returns True if object has error-like structure.\n */\nexport function hasErrorShape(error: unknown): error is { message: string; status?: number; code?: string } {\n return (\n typeof error === 'object' && error !== null && 'message' in error && typeof (error as any).message === 'string'\n );\n}\n\n/**\n * Safely extracts message from any error type.\n *\n * @param error - Any error object or value.\n * @returns A string error message.\n */\nexport function getErrorMessage(error: unknown): string {\n if (typeof error === 'string') {\n return error;\n }\n\n if (error instanceof Error) {\n return error.message;\n }\n\n if (hasErrorShape(error)) {\n return error.message;\n }\n\n return 'Unknown error occurred';\n}\n\n/**\n * Wraps a function and transforms any errors into HTTP errors.\n * Useful for API handlers to ensure consistent error responses.\n *\n * @param handler - The async function to wrap.\n * @returns A function that always returns or throws an HTTP error.\n */\nexport function withErrorHandling<T extends (...args: any[]) => Promise<any>>(\n handler: T\n): (...args: Parameters<T>) => Promise<Awaited<ReturnType<T>>> {\n return async (...args: Parameters<T>) => {\n try {\n return await handler(...args);\n } catch (err) {\n if (isHttpError(err)) {\n throw err;\n }\n\n // Log the original error (consider using a proper logger)\n getLogger().error({ err }, 'Caught error in handler');\n\n // Extract status code if it exists, otherwise use 500\n let status = HttpStatusCodes.INTERNAL_SERVER_ERROR;\n if (hasErrorShape(err) && typeof err.status === 'number') {\n status = err.status;\n }\n\n // Create appropriate HTTP error\n throw createHttpError(status, getErrorMessage(err));\n }\n };\n}\n"]}
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import { BufferEncoding } from './crypto.utils';
|
|
2
|
-
import { Stats } from 'fs';
|
|
3
|
-
/**
|
|
4
|
-
* Checks whether a file or directory exists at the given path.
|
|
5
|
-
*
|
|
6
|
-
* @param {string} path - The file or directory path to check.
|
|
7
|
-
* @returns {Promise<boolean>} Resolves to `true` if the path exists, `false` otherwise.
|
|
8
|
-
*/
|
|
9
|
-
export declare function fileExists(path: string): Promise<boolean>;
|
|
10
|
-
/**
|
|
11
|
-
* Reads and parses a JSON file from the specified path.
|
|
12
|
-
*
|
|
13
|
-
* @typeParam T - The expected type of the parsed JSON object.
|
|
14
|
-
* @param {string} path - The path to the JSON file.
|
|
15
|
-
* @returns {Promise<T | null>} The parsed object, or `null` if reading or parsing fails.
|
|
16
|
-
*/
|
|
17
|
-
export declare function readJsonFile<T = any>(path: string): Promise<T | null>;
|
|
18
|
-
/**
|
|
19
|
-
* Writes a JavaScript object to a file as formatted JSON.
|
|
20
|
-
*
|
|
21
|
-
* @param {string} path - The destination file path.
|
|
22
|
-
* @param {any} data - The object to serialize and write.
|
|
23
|
-
* @param {number} [space=2] - Number of spaces for JSON formatting.
|
|
24
|
-
* @returns {Promise<void>} Resolves when writing is complete.
|
|
25
|
-
*/
|
|
26
|
-
export declare function writeJsonFile(path: string, data: any, space?: number): Promise<void>;
|
|
27
|
-
/**
|
|
28
|
-
* Deletes a file if it exists.
|
|
29
|
-
*
|
|
30
|
-
* @param {string} path - The file path to delete.
|
|
31
|
-
* @returns {Promise<boolean>} Resolves to `true` if the file was deleted or didn't exist, `false` if deletion failed.
|
|
32
|
-
*/
|
|
33
|
-
export declare function deleteFileIfExists(path: string): Promise<boolean>;
|
|
34
|
-
/**
|
|
35
|
-
* Reads a text file from the specified path.
|
|
36
|
-
*
|
|
37
|
-
* @param {string} path - The path to the text file.
|
|
38
|
-
* @param {BufferEncoding} [encoding="utf-8"] - The encoding to use.
|
|
39
|
-
* @returns {Promise<string | null>} The file contents, or `null` if reading fails.
|
|
40
|
-
*/
|
|
41
|
-
export declare function readTextFile(path: string, encoding?: BufferEncoding): Promise<string | null>;
|
|
42
|
-
/**
|
|
43
|
-
* Writes text content to a file.
|
|
44
|
-
*
|
|
45
|
-
* @param {string} path - The destination file path.
|
|
46
|
-
* @param {string} content - The text content to write.
|
|
47
|
-
* @param {BufferEncoding} [encoding="utf-8"] - The encoding to use.
|
|
48
|
-
* @returns {Promise<boolean>} Resolves to `true` if successful, `false` otherwise.
|
|
49
|
-
*/
|
|
50
|
-
export declare function writeTextFile(path: string, content: string, encoding?: BufferEncoding): Promise<boolean>;
|
|
51
|
-
/**
|
|
52
|
-
* Appends text content to a file.
|
|
53
|
-
*
|
|
54
|
-
* @param {string} path - The file path to append to.
|
|
55
|
-
* @param {string} content - The text content to append.
|
|
56
|
-
* @param {BufferEncoding} [encoding="utf-8"] - The encoding to use.
|
|
57
|
-
* @returns {Promise<boolean>} Resolves to `true` if successful, `false` otherwise.
|
|
58
|
-
*/
|
|
59
|
-
export declare function appendTextFile(path: string, content: string, encoding?: BufferEncoding): Promise<boolean>;
|
|
60
|
-
/**
|
|
61
|
-
* Copies a file from source to destination.
|
|
62
|
-
*
|
|
63
|
-
* @param {string} source - Source file path.
|
|
64
|
-
* @param {string} destination - Destination file path.
|
|
65
|
-
* @param {boolean} [overwrite=false] - Whether to overwrite if destination exists.
|
|
66
|
-
* @returns {Promise<boolean>} Resolves to `true` if successful, `false` otherwise.
|
|
67
|
-
*/
|
|
68
|
-
export declare function copyFile(source: string, destination: string, overwrite?: boolean): Promise<boolean>;
|
|
69
|
-
/**
|
|
70
|
-
* Renames/moves a file.
|
|
71
|
-
*
|
|
72
|
-
* @param {string} oldPath - Current file path.
|
|
73
|
-
* @param {string} newPath - New file path.
|
|
74
|
-
* @returns {Promise<boolean>} Resolves to `true` if successful, `false` otherwise.
|
|
75
|
-
*/
|
|
76
|
-
export declare function moveFile(oldPath: string, newPath: string): Promise<boolean>;
|
|
77
|
-
/**
|
|
78
|
-
* Gets file stats if the file exists.
|
|
79
|
-
*
|
|
80
|
-
* @param {string} path - Path to the file.
|
|
81
|
-
* @returns {Promise<fs.Stats | null>} File stats object or null if file doesn't exist.
|
|
82
|
-
*/
|
|
83
|
-
export declare function getFileStats(path: string): Promise<Stats | null>;
|
|
84
|
-
/**
|
|
85
|
-
* Creates a temporary file with optional content.
|
|
86
|
-
*
|
|
87
|
-
* @param {object} [options] - Options for creating the temp file.
|
|
88
|
-
* @param {string} [options.prefix="tmp-"] - Filename prefix.
|
|
89
|
-
* @param {string} [options.extension=""] - File extension.
|
|
90
|
-
* @param {string} [options.dir] - Directory to create the file in (defaults to OS temp dir).
|
|
91
|
-
* @param {string | Buffer} [options.content] - Optional content to write to the file.
|
|
92
|
-
* @returns {Promise<string>} Path to the created temporary file.
|
|
93
|
-
*/
|
|
94
|
-
export declare function createTempFile({ prefix, extension, dir, content }?: {
|
|
95
|
-
prefix?: string;
|
|
96
|
-
extension?: string;
|
|
97
|
-
dir?: string;
|
|
98
|
-
content?: string | Buffer;
|
|
99
|
-
}): Promise<string>;
|
|
100
|
-
/**
|
|
101
|
-
* Streams a file from source to destination.
|
|
102
|
-
* Useful for large files to avoid loading the entire file into memory.
|
|
103
|
-
*
|
|
104
|
-
* @param {string} source - Source file path.
|
|
105
|
-
* @param {string} destination - Destination file path.
|
|
106
|
-
* @returns {Promise<void>} Resolves when streaming completes.
|
|
107
|
-
* @throws {Error} If streaming fails.
|
|
108
|
-
*/
|
|
109
|
-
export declare function streamFile(source: string, destination: string): Promise<void>;
|
|
110
|
-
/**
|
|
111
|
-
* Reads a directory and returns file names.
|
|
112
|
-
*
|
|
113
|
-
* @param {string} dirPath - Path to the directory.
|
|
114
|
-
* @param {object} [options] - Options for reading the directory.
|
|
115
|
-
* @param {boolean} [options.fullPaths=false] - Whether to return full paths.
|
|
116
|
-
* @param {RegExp} [options.filter] - Optional regex to filter files.
|
|
117
|
-
* @returns {Promise<string[]>} Array of file names or paths.
|
|
118
|
-
* @throws {Error} If directory cannot be read.
|
|
119
|
-
*/
|
|
120
|
-
export declare function readDirectory(dirPath: string, options?: {
|
|
121
|
-
fullPaths?: boolean;
|
|
122
|
-
filter?: RegExp;
|
|
123
|
-
}): Promise<string[]>;
|
|
124
|
-
/**
|
|
125
|
-
* Creates a directory if it doesn't exist.
|
|
126
|
-
*
|
|
127
|
-
* @param {string} dirPath - Path to the directory.
|
|
128
|
-
* @param {boolean} [recursive=true] - Whether to create parent directories.
|
|
129
|
-
* @returns {Promise<boolean>} Resolves to `true` if successful, `false` otherwise.
|
|
130
|
-
*/
|
|
131
|
-
export declare function createDirectory(dirPath: string, recursive?: boolean): Promise<boolean>;
|
|
132
|
-
/**
|
|
133
|
-
* Safely reads and parses a JSON file with error details.
|
|
134
|
-
*
|
|
135
|
-
* @typeParam T - The expected type of the parsed JSON object.
|
|
136
|
-
* @param {string} path - The path to the JSON file.
|
|
137
|
-
* @returns {Promise<{ data: T | null; error: Error | null }>} Object with data and error properties.
|
|
138
|
-
*/
|
|
139
|
-
export declare function safeReadJsonFile<T = any>(path: string): Promise<{
|
|
140
|
-
data: T | null;
|
|
141
|
-
error: Error | null;
|
|
142
|
-
}>;
|
|
143
|
-
/**
|
|
144
|
-
* Checks if a path points to a file (not a directory).
|
|
145
|
-
*
|
|
146
|
-
* @param {string} path - Path to check.
|
|
147
|
-
* @returns {Promise<boolean>} True if the path is a file, false otherwise.
|
|
148
|
-
*/
|
|
149
|
-
export declare function isFile(path: string): Promise<boolean>;
|
|
150
|
-
/**
|
|
151
|
-
* Gets the size of a file in bytes.
|
|
152
|
-
*
|
|
153
|
-
* @param {string} path - Path to the file.
|
|
154
|
-
* @returns {Promise<number>} Size in bytes or -1 if file doesn't exist.
|
|
155
|
-
*/
|
|
156
|
-
export declare function getFileSize(path: string): Promise<number>;
|
|
157
|
-
/**
|
|
158
|
-
* Reads a file as a Buffer.
|
|
159
|
-
*
|
|
160
|
-
* @param {string} path - Path to the file.
|
|
161
|
-
* @returns {Promise<Buffer | null>} File contents as Buffer or null if reading fails.
|
|
162
|
-
*/
|
|
163
|
-
export declare function readFileBuffer(path: string): Promise<Buffer | null>;
|
|
164
|
-
//# sourceMappingURL=fs.utils.d.ts.map
|