@catbee/utils 0.0.8-next.0 → 0.0.8-rc.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.
Files changed (284) hide show
  1. package/README.md +1 -2
  2. package/build/esm/config.d.ts +122 -0
  3. package/build/esm/config.js +133 -0
  4. package/build/esm/config.js.map +1 -0
  5. package/build/esm/index.d.ts +27 -0
  6. package/build/esm/index.js +50 -0
  7. package/build/esm/index.js.map +1 -0
  8. package/build/esm/servers/server.builder.d.ts +508 -0
  9. package/build/esm/servers/server.builder.js +702 -0
  10. package/build/esm/servers/server.builder.js.map +1 -0
  11. package/build/esm/servers/server.d.ts +256 -0
  12. package/build/esm/servers/server.js +1248 -0
  13. package/build/esm/servers/server.js.map +1 -0
  14. package/build/esm/types/api-response.d.ts +152 -0
  15. package/build/esm/types/api-response.js +34 -0
  16. package/build/esm/types/api-response.js.map +1 -0
  17. package/build/esm/types/index.d.ts +125 -0
  18. package/build/esm/types/index.js +25 -0
  19. package/build/esm/types/index.js.map +1 -0
  20. package/build/esm/types/server.d.ts +268 -0
  21. package/build/esm/types/server.js +25 -0
  22. package/build/esm/types/server.js.map +1 -0
  23. package/build/esm/utils/array.utils.d.ts +168 -0
  24. package/build/esm/utils/array.utils.js +382 -0
  25. package/build/esm/utils/array.utils.js.map +1 -0
  26. package/build/esm/utils/async.utils.d.ts +265 -0
  27. package/build/esm/utils/async.utils.js +896 -0
  28. package/build/esm/utils/async.utils.js.map +1 -0
  29. package/build/esm/utils/cache.utils.d.ts +153 -0
  30. package/build/esm/utils/cache.utils.js +499 -0
  31. package/build/esm/utils/cache.utils.js.map +1 -0
  32. package/build/esm/utils/context-store.utils.d.ts +189 -0
  33. package/build/esm/utils/context-store.utils.js +307 -0
  34. package/build/esm/utils/context-store.utils.js.map +1 -0
  35. package/build/esm/utils/crypto.utils.d.ts +160 -0
  36. package/build/esm/utils/crypto.utils.js +375 -0
  37. package/build/esm/utils/crypto.utils.js.map +1 -0
  38. package/build/esm/utils/date.utils.d.ts +159 -0
  39. package/build/esm/utils/date.utils.js +389 -0
  40. package/build/esm/utils/date.utils.js.map +1 -0
  41. package/build/esm/utils/decorators.utils.d.ts +508 -0
  42. package/build/esm/utils/decorators.utils.js +1057 -0
  43. package/build/esm/utils/decorators.utils.js.map +1 -0
  44. package/build/esm/utils/dir.utils.d.ts +196 -0
  45. package/build/esm/utils/dir.utils.js +998 -0
  46. package/build/esm/utils/dir.utils.js.map +1 -0
  47. package/build/esm/utils/env.utils.d.ts +377 -0
  48. package/build/esm/utils/env.utils.js +873 -0
  49. package/build/esm/utils/env.utils.js.map +1 -0
  50. package/build/esm/utils/exception.utils.d.ts +230 -0
  51. package/build/esm/utils/exception.utils.js +559 -0
  52. package/build/esm/utils/exception.utils.js.map +1 -0
  53. package/build/esm/utils/fs.utils.d.ts +164 -0
  54. package/build/esm/utils/fs.utils.js +580 -0
  55. package/build/esm/utils/fs.utils.js.map +1 -0
  56. package/build/esm/utils/http-status-codes.d.ts +266 -0
  57. package/build/esm/utils/http-status-codes.js +295 -0
  58. package/build/esm/utils/http-status-codes.js.map +1 -0
  59. package/build/esm/utils/id.utils.d.ts +36 -0
  60. package/build/esm/utils/id.utils.js +87 -0
  61. package/build/esm/utils/id.utils.js.map +1 -0
  62. package/build/esm/utils/logger.utils.d.ts +160 -0
  63. package/build/esm/utils/logger.utils.js +341 -0
  64. package/build/esm/utils/logger.utils.js.map +1 -0
  65. package/build/esm/utils/middleware.utils.d.ts +100 -0
  66. package/build/esm/utils/middleware.utils.js +325 -0
  67. package/build/esm/utils/middleware.utils.js.map +1 -0
  68. package/build/esm/utils/obj.utils.d.ts +124 -0
  69. package/build/esm/utils/obj.utils.js +519 -0
  70. package/build/esm/utils/obj.utils.js.map +1 -0
  71. package/build/esm/utils/performance.utils.d.ts +136 -0
  72. package/build/esm/utils/performance.utils.js +376 -0
  73. package/build/esm/utils/performance.utils.js.map +1 -0
  74. package/build/esm/utils/request.utils.d.ts +86 -0
  75. package/build/esm/utils/request.utils.js +223 -0
  76. package/build/esm/utils/request.utils.js.map +1 -0
  77. package/build/esm/utils/response.utils.d.ts +163 -0
  78. package/build/esm/utils/response.utils.js +284 -0
  79. package/build/esm/utils/response.utils.js.map +1 -0
  80. package/build/esm/utils/stream.utils.d.ts +88 -0
  81. package/build/esm/utils/stream.utils.js +284 -0
  82. package/build/esm/utils/stream.utils.js.map +1 -0
  83. package/build/esm/utils/string.utils.d.ts +93 -0
  84. package/build/esm/utils/string.utils.js +169 -0
  85. package/build/esm/utils/string.utils.js.map +1 -0
  86. package/build/esm/utils/type.utils.d.ts +90 -0
  87. package/build/esm/utils/type.utils.js +190 -0
  88. package/build/esm/utils/type.utils.js.map +1 -0
  89. package/build/esm/utils/url.utils.d.ts +141 -0
  90. package/build/esm/utils/url.utils.js +381 -0
  91. package/build/esm/utils/url.utils.js.map +1 -0
  92. package/build/esm/utils/validate.utils.d.ts +177 -0
  93. package/build/esm/utils/validate.utils.js +336 -0
  94. package/build/esm/utils/validate.utils.js.map +1 -0
  95. package/build/esnext/config.d.ts +122 -0
  96. package/build/esnext/config.js +133 -0
  97. package/build/esnext/config.js.map +1 -0
  98. package/build/esnext/index.d.ts +27 -0
  99. package/build/esnext/index.js +50 -0
  100. package/build/esnext/index.js.map +1 -0
  101. package/build/esnext/servers/server.builder.d.ts +508 -0
  102. package/build/esnext/servers/server.builder.js +657 -0
  103. package/build/esnext/servers/server.builder.js.map +1 -0
  104. package/build/esnext/servers/server.d.ts +256 -0
  105. package/build/esnext/servers/server.js +955 -0
  106. package/build/esnext/servers/server.js.map +1 -0
  107. package/build/esnext/types/api-response.d.ts +152 -0
  108. package/build/esnext/types/api-response.js +34 -0
  109. package/build/esnext/types/api-response.js.map +1 -0
  110. package/build/esnext/types/index.d.ts +125 -0
  111. package/build/esnext/types/index.js +25 -0
  112. package/build/esnext/types/index.js.map +1 -0
  113. package/build/esnext/types/server.d.ts +268 -0
  114. package/build/esnext/types/server.js +25 -0
  115. package/build/esnext/types/server.js.map +1 -0
  116. package/build/esnext/utils/array.utils.d.ts +168 -0
  117. package/build/esnext/utils/array.utils.js +345 -0
  118. package/build/esnext/utils/array.utils.js.map +1 -0
  119. package/build/esnext/utils/async.utils.d.ts +265 -0
  120. package/build/esnext/utils/async.utils.js +620 -0
  121. package/build/esnext/utils/async.utils.js.map +1 -0
  122. package/build/esnext/utils/cache.utils.d.ts +153 -0
  123. package/build/esnext/utils/cache.utils.js +293 -0
  124. package/build/esnext/utils/cache.utils.js.map +1 -0
  125. package/build/esnext/utils/context-store.utils.d.ts +189 -0
  126. package/build/esnext/utils/context-store.utils.js +289 -0
  127. package/build/esnext/utils/context-store.utils.js.map +1 -0
  128. package/build/esnext/utils/crypto.utils.d.ts +160 -0
  129. package/build/esnext/utils/crypto.utils.js +276 -0
  130. package/build/esnext/utils/crypto.utils.js.map +1 -0
  131. package/build/esnext/utils/date.utils.d.ts +159 -0
  132. package/build/esnext/utils/date.utils.js +384 -0
  133. package/build/esnext/utils/date.utils.js.map +1 -0
  134. package/build/esnext/utils/decorators.utils.d.ts +508 -0
  135. package/build/esnext/utils/decorators.utils.js +877 -0
  136. package/build/esnext/utils/decorators.utils.js.map +1 -0
  137. package/build/esnext/utils/dir.utils.d.ts +196 -0
  138. package/build/esnext/utils/dir.utils.js +477 -0
  139. package/build/esnext/utils/dir.utils.js.map +1 -0
  140. package/build/esnext/utils/env.utils.d.ts +377 -0
  141. package/build/esnext/utils/env.utils.js +785 -0
  142. package/build/esnext/utils/env.utils.js.map +1 -0
  143. package/build/esnext/utils/exception.utils.d.ts +230 -0
  144. package/build/esnext/utils/exception.utils.js +381 -0
  145. package/build/esnext/utils/exception.utils.js.map +1 -0
  146. package/build/esnext/utils/fs.utils.d.ts +164 -0
  147. package/build/esnext/utils/fs.utils.js +349 -0
  148. package/build/esnext/utils/fs.utils.js.map +1 -0
  149. package/build/esnext/utils/http-status-codes.d.ts +266 -0
  150. package/build/esnext/utils/http-status-codes.js +295 -0
  151. package/build/esnext/utils/http-status-codes.js.map +1 -0
  152. package/build/esnext/utils/id.utils.d.ts +36 -0
  153. package/build/esnext/utils/id.utils.js +84 -0
  154. package/build/esnext/utils/id.utils.js.map +1 -0
  155. package/build/esnext/utils/logger.utils.d.ts +160 -0
  156. package/build/esnext/utils/logger.utils.js +300 -0
  157. package/build/esnext/utils/logger.utils.js.map +1 -0
  158. package/build/esnext/utils/middleware.utils.d.ts +100 -0
  159. package/build/esnext/utils/middleware.utils.js +236 -0
  160. package/build/esnext/utils/middleware.utils.js.map +1 -0
  161. package/build/esnext/utils/obj.utils.d.ts +124 -0
  162. package/build/esnext/utils/obj.utils.js +413 -0
  163. package/build/esnext/utils/obj.utils.js.map +1 -0
  164. package/build/esnext/utils/performance.utils.d.ts +136 -0
  165. package/build/esnext/utils/performance.utils.js +271 -0
  166. package/build/esnext/utils/performance.utils.js.map +1 -0
  167. package/build/esnext/utils/request.utils.d.ts +86 -0
  168. package/build/esnext/utils/request.utils.js +186 -0
  169. package/build/esnext/utils/request.utils.js.map +1 -0
  170. package/build/esnext/utils/response.utils.d.ts +163 -0
  171. package/build/esnext/utils/response.utils.js +247 -0
  172. package/build/esnext/utils/response.utils.js.map +1 -0
  173. package/build/esnext/utils/stream.utils.d.ts +88 -0
  174. package/build/esnext/utils/stream.utils.js +210 -0
  175. package/build/esnext/utils/stream.utils.js.map +1 -0
  176. package/build/esnext/utils/string.utils.d.ts +93 -0
  177. package/build/esnext/utils/string.utils.js +165 -0
  178. package/build/esnext/utils/string.utils.js.map +1 -0
  179. package/build/esnext/utils/type.utils.d.ts +90 -0
  180. package/build/esnext/utils/type.utils.js +187 -0
  181. package/build/esnext/utils/type.utils.js.map +1 -0
  182. package/build/esnext/utils/url.utils.d.ts +141 -0
  183. package/build/esnext/utils/url.utils.js +304 -0
  184. package/build/esnext/utils/url.utils.js.map +1 -0
  185. package/build/esnext/utils/validate.utils.d.ts +177 -0
  186. package/build/esnext/utils/validate.utils.js +320 -0
  187. package/build/esnext/utils/validate.utils.js.map +1 -0
  188. package/build/src/config.d.ts +122 -0
  189. package/build/src/config.js +138 -0
  190. package/build/src/config.js.map +1 -0
  191. package/build/src/index.d.ts +27 -0
  192. package/build/src/index.js +69 -0
  193. package/build/src/index.js.map +1 -0
  194. package/build/src/servers/server.builder.d.ts +508 -0
  195. package/build/src/servers/server.builder.js +661 -0
  196. package/build/src/servers/server.builder.js.map +1 -0
  197. package/build/src/servers/server.d.ts +256 -0
  198. package/build/src/servers/server.js +962 -0
  199. package/build/src/servers/server.js.map +1 -0
  200. package/build/src/types/api-response.d.ts +152 -0
  201. package/build/src/types/api-response.js +37 -0
  202. package/build/src/types/api-response.js.map +1 -0
  203. package/build/src/types/index.d.ts +125 -0
  204. package/build/src/types/index.js +26 -0
  205. package/build/src/types/index.js.map +1 -0
  206. package/build/src/types/server.d.ts +268 -0
  207. package/build/src/types/server.js +26 -0
  208. package/build/src/types/server.js.map +1 -0
  209. package/build/src/utils/array.utils.d.ts +168 -0
  210. package/build/src/utils/array.utils.js +364 -0
  211. package/build/src/utils/array.utils.js.map +1 -0
  212. package/build/src/utils/async.utils.d.ts +265 -0
  213. package/build/src/utils/async.utils.js +641 -0
  214. package/build/src/utils/async.utils.js.map +1 -0
  215. package/build/src/utils/cache.utils.d.ts +153 -0
  216. package/build/src/utils/cache.utils.js +297 -0
  217. package/build/src/utils/cache.utils.js.map +1 -0
  218. package/build/src/utils/context-store.utils.d.ts +189 -0
  219. package/build/src/utils/context-store.utils.js +296 -0
  220. package/build/src/utils/context-store.utils.js.map +1 -0
  221. package/build/src/utils/crypto.utils.d.ts +160 -0
  222. package/build/src/utils/crypto.utils.js +293 -0
  223. package/build/src/utils/crypto.utils.js.map +1 -0
  224. package/build/src/utils/date.utils.d.ts +159 -0
  225. package/build/src/utils/date.utils.js +396 -0
  226. package/build/src/utils/date.utils.js.map +1 -0
  227. package/build/src/utils/decorators.utils.d.ts +508 -0
  228. package/build/src/utils/decorators.utils.js +896 -0
  229. package/build/src/utils/decorators.utils.js.map +1 -0
  230. package/build/src/utils/dir.utils.d.ts +196 -0
  231. package/build/src/utils/dir.utils.js +501 -0
  232. package/build/src/utils/dir.utils.js.map +1 -0
  233. package/build/src/utils/env.utils.d.ts +377 -0
  234. package/build/src/utils/env.utils.js +789 -0
  235. package/build/src/utils/env.utils.js.map +1 -0
  236. package/build/src/utils/exception.utils.d.ts +230 -0
  237. package/build/src/utils/exception.utils.js +407 -0
  238. package/build/src/utils/exception.utils.js.map +1 -0
  239. package/build/src/utils/fs.utils.d.ts +164 -0
  240. package/build/src/utils/fs.utils.js +372 -0
  241. package/build/src/utils/fs.utils.js.map +1 -0
  242. package/build/src/utils/http-status-codes.d.ts +266 -0
  243. package/build/src/utils/http-status-codes.js +298 -0
  244. package/build/src/utils/http-status-codes.js.map +1 -0
  245. package/build/src/utils/id.utils.d.ts +36 -0
  246. package/build/src/utils/id.utils.js +91 -0
  247. package/build/src/utils/id.utils.js.map +1 -0
  248. package/build/src/utils/logger.utils.d.ts +160 -0
  249. package/build/src/utils/logger.utils.js +346 -0
  250. package/build/src/utils/logger.utils.js.map +1 -0
  251. package/build/src/utils/middleware.utils.d.ts +100 -0
  252. package/build/src/utils/middleware.utils.js +244 -0
  253. package/build/src/utils/middleware.utils.js.map +1 -0
  254. package/build/src/utils/obj.utils.d.ts +124 -0
  255. package/build/src/utils/obj.utils.js +429 -0
  256. package/build/src/utils/obj.utils.js.map +1 -0
  257. package/build/src/utils/performance.utils.d.ts +136 -0
  258. package/build/src/utils/performance.utils.js +278 -0
  259. package/build/src/utils/performance.utils.js.map +1 -0
  260. package/build/src/utils/request.utils.d.ts +86 -0
  261. package/build/src/utils/request.utils.js +195 -0
  262. package/build/src/utils/request.utils.js.map +1 -0
  263. package/build/src/utils/response.utils.d.ts +163 -0
  264. package/build/src/utils/response.utils.js +260 -0
  265. package/build/src/utils/response.utils.js.map +1 -0
  266. package/build/src/utils/stream.utils.d.ts +88 -0
  267. package/build/src/utils/stream.utils.js +218 -0
  268. package/build/src/utils/stream.utils.js.map +1 -0
  269. package/build/src/utils/string.utils.d.ts +93 -0
  270. package/build/src/utils/string.utils.js +179 -0
  271. package/build/src/utils/string.utils.js.map +1 -0
  272. package/build/src/utils/type.utils.d.ts +90 -0
  273. package/build/src/utils/type.utils.js +196 -0
  274. package/build/src/utils/type.utils.js.map +1 -0
  275. package/build/src/utils/url.utils.d.ts +141 -0
  276. package/build/src/utils/url.utils.js +317 -0
  277. package/build/src/utils/url.utils.js.map +1 -0
  278. package/build/src/utils/validate.utils.d.ts +177 -0
  279. package/build/src/utils/validate.utils.js +345 -0
  280. package/build/src/utils/validate.utils.js.map +1 -0
  281. package/package.json +66 -12
  282. package/build/index.cjs +0 -6888
  283. package/build/index.d.ts +0 -5242
  284. package/build/index.mjs +0 -6615
@@ -0,0 +1,559 @@
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
+ var __extends = (this && this.__extends) || (function () {
25
+ var extendStatics = function (d, b) {
26
+ extendStatics = Object.setPrototypeOf ||
27
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
28
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
29
+ return extendStatics(d, b);
30
+ };
31
+ return function (d, b) {
32
+ if (typeof b !== "function" && b !== null)
33
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
34
+ extendStatics(d, b);
35
+ function __() { this.constructor = d; }
36
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
37
+ };
38
+ })();
39
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
40
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
41
+ return new (P || (P = Promise))(function (resolve, reject) {
42
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
43
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
44
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
45
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
46
+ });
47
+ };
48
+ var __generator = (this && this.__generator) || function (thisArg, body) {
49
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
50
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
51
+ function verb(n) { return function (v) { return step([n, v]); }; }
52
+ function step(op) {
53
+ if (f) throw new TypeError("Generator is already executing.");
54
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
55
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
56
+ if (y = 0, t) op = [op[0] & 2, t.value];
57
+ switch (op[0]) {
58
+ case 0: case 1: t = op; break;
59
+ case 4: _.label++; return { value: op[1], done: false };
60
+ case 5: _.label++; y = op[1]; op = [0]; continue;
61
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
62
+ default:
63
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
64
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
65
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
66
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
67
+ if (t[2]) _.ops.pop();
68
+ _.trys.pop(); continue;
69
+ }
70
+ op = body.call(thisArg, _);
71
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
72
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
73
+ }
74
+ };
75
+ var __read = (this && this.__read) || function (o, n) {
76
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
77
+ if (!m) return o;
78
+ var i = m.call(o), r, ar = [], e;
79
+ try {
80
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
81
+ }
82
+ catch (error) { e = { error: error }; }
83
+ finally {
84
+ try {
85
+ if (r && !r.done && (m = i["return"])) m.call(i);
86
+ }
87
+ finally { if (e) throw e.error; }
88
+ }
89
+ return ar;
90
+ };
91
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
92
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
93
+ if (ar || !(i in from)) {
94
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
95
+ ar[i] = from[i];
96
+ }
97
+ }
98
+ return to.concat(ar || Array.prototype.slice.call(from));
99
+ };
100
+ import { HttpStatusCodes } from './http-status-codes';
101
+ import { getLogger } from './logger.utils';
102
+ import { ErrorResponse } from './response.utils';
103
+ /**
104
+ * Generic HTTP error class used for custom exceptions with any status code.
105
+ * Inherit this when you need to throw errors dynamically at runtime.
106
+ */
107
+ var HttpError = /** @class */ (function (_super) {
108
+ __extends(HttpError, _super);
109
+ /**
110
+ * Creates a new HTTP error instance.
111
+ * @param status - A valid HTTP status code (e.g., 400, 500).
112
+ * @param message - The error message to return to the client.
113
+ */
114
+ function HttpError(status, message) {
115
+ var _this = _super.call(this, message) || this;
116
+ _this.status = status;
117
+ return _this;
118
+ }
119
+ return HttpError;
120
+ }(ErrorResponse));
121
+ export { HttpError };
122
+ /**
123
+ * Represents a 500 Internal Server Error.
124
+ * Use this for unexpected backend errors that are not caused by the client.
125
+ */
126
+ var InternalServerErrorException = /** @class */ (function (_super) {
127
+ __extends(InternalServerErrorException, _super);
128
+ /**
129
+ * @param message - Optional custom message. Defaults to "Internal server error".
130
+ */
131
+ function InternalServerErrorException(message) {
132
+ if (message === void 0) { message = 'Internal server error'; }
133
+ var _this = _super.call(this, message) || this;
134
+ _this.status = HttpStatusCodes.INTERNAL_SERVER_ERROR;
135
+ return _this;
136
+ }
137
+ return InternalServerErrorException;
138
+ }(ErrorResponse));
139
+ export { InternalServerErrorException };
140
+ /**
141
+ * Represents a 401 Unauthorized Error.
142
+ * Indicates that authentication is required and has failed or not been provided.
143
+ */
144
+ var UnauthorizedException = /** @class */ (function (_super) {
145
+ __extends(UnauthorizedException, _super);
146
+ /**
147
+ * @param message - Optional custom message. Defaults to "Unauthorized".
148
+ */
149
+ function UnauthorizedException(message) {
150
+ if (message === void 0) { message = 'Unauthorized'; }
151
+ var _this = _super.call(this, message) || this;
152
+ _this.status = HttpStatusCodes.UNAUTHORIZED;
153
+ return _this;
154
+ }
155
+ return UnauthorizedException;
156
+ }(ErrorResponse));
157
+ export { UnauthorizedException };
158
+ /**
159
+ * Represents a 400 Bad Request Error.
160
+ * Indicates that the client has sent invalid data (e.g., malformed request body).
161
+ */
162
+ var BadRequestException = /** @class */ (function (_super) {
163
+ __extends(BadRequestException, _super);
164
+ /**
165
+ * @param message - Optional custom message. Defaults to "Bad request".
166
+ */
167
+ function BadRequestException(message) {
168
+ if (message === void 0) { message = 'Bad request'; }
169
+ var _this = _super.call(this, message) || this;
170
+ _this.status = HttpStatusCodes.BAD_REQUEST;
171
+ return _this;
172
+ }
173
+ return BadRequestException;
174
+ }(ErrorResponse));
175
+ export { BadRequestException };
176
+ /**
177
+ * Represents a 404 Not Found Error.
178
+ * Used when a requested resource (e.g., user, file) could not be located.
179
+ */
180
+ var NotFoundException = /** @class */ (function (_super) {
181
+ __extends(NotFoundException, _super);
182
+ /**
183
+ * @param message - Optional custom message. Defaults to "Resource not found".
184
+ */
185
+ function NotFoundException(message) {
186
+ if (message === void 0) { message = 'Resource not found'; }
187
+ var _this = _super.call(this, message) || this;
188
+ _this.status = HttpStatusCodes.NOT_FOUND;
189
+ return _this;
190
+ }
191
+ return NotFoundException;
192
+ }(ErrorResponse));
193
+ export { NotFoundException };
194
+ /**
195
+ * Represents a 403 Forbidden Error.
196
+ * Indicates that the client is authenticated but not allowed to access the resource.
197
+ */
198
+ var ForbiddenException = /** @class */ (function (_super) {
199
+ __extends(ForbiddenException, _super);
200
+ /**
201
+ * @param message - Optional custom message. Defaults to "Forbidden".
202
+ */
203
+ function ForbiddenException(message) {
204
+ if (message === void 0) { message = 'Forbidden'; }
205
+ var _this = _super.call(this, message) || this;
206
+ _this.status = HttpStatusCodes.FORBIDDEN;
207
+ return _this;
208
+ }
209
+ return ForbiddenException;
210
+ }(ErrorResponse));
211
+ export { ForbiddenException };
212
+ /**
213
+ * Represents a 409 Conflict Error.
214
+ * Commonly used when a resource already exists or a versioning conflict occurs.
215
+ */
216
+ var ConflictException = /** @class */ (function (_super) {
217
+ __extends(ConflictException, _super);
218
+ /**
219
+ * @param message - Optional custom message. Defaults to "Conflict".
220
+ */
221
+ function ConflictException(message) {
222
+ if (message === void 0) { message = 'Conflict'; }
223
+ var _this = _super.call(this, message) || this;
224
+ _this.status = HttpStatusCodes.CONFLICT;
225
+ return _this;
226
+ }
227
+ return ConflictException;
228
+ }(ErrorResponse));
229
+ export { ConflictException };
230
+ /**
231
+ * Represents a 502 Bad Gateway Error.
232
+ * Used when the server receives an invalid response from an upstream server.
233
+ */
234
+ var BadGatewayException = /** @class */ (function (_super) {
235
+ __extends(BadGatewayException, _super);
236
+ /**
237
+ * @param message - Optional custom message. Defaults to "Bad Gateway".
238
+ */
239
+ function BadGatewayException(message) {
240
+ if (message === void 0) { message = 'Bad Gateway'; }
241
+ var _this = _super.call(this, message) || this;
242
+ _this.status = HttpStatusCodes.BAD_GATEWAY;
243
+ return _this;
244
+ }
245
+ return BadGatewayException;
246
+ }(ErrorResponse));
247
+ export { BadGatewayException };
248
+ /**
249
+ * Represents a 429 Too Many Requests Error.
250
+ * Returned when the client has hit a rate limit.
251
+ */
252
+ var TooManyRequestsException = /** @class */ (function (_super) {
253
+ __extends(TooManyRequestsException, _super);
254
+ /**
255
+ * @param message - Optional custom message. Defaults to "Too many requests".
256
+ */
257
+ function TooManyRequestsException(message) {
258
+ if (message === void 0) { message = 'Too many requests'; }
259
+ var _this = _super.call(this, message) || this;
260
+ _this.status = HttpStatusCodes.TOO_MANY_REQUESTS;
261
+ return _this;
262
+ }
263
+ return TooManyRequestsException;
264
+ }(ErrorResponse));
265
+ export { TooManyRequestsException };
266
+ /**
267
+ * Represents a 503 Service Unavailable Error.
268
+ * Indicates that the server is temporarily unavailable (e.g., for maintenance).
269
+ */
270
+ var ServiceUnavailableException = /** @class */ (function (_super) {
271
+ __extends(ServiceUnavailableException, _super);
272
+ /**
273
+ * @param message - Optional custom message. Defaults to "Service Unavailable".
274
+ */
275
+ function ServiceUnavailableException(message) {
276
+ if (message === void 0) { message = 'Service Unavailable'; }
277
+ var _this = _super.call(this, message) || this;
278
+ _this.status = HttpStatusCodes.SERVICE_UNAVAILABLE;
279
+ return _this;
280
+ }
281
+ return ServiceUnavailableException;
282
+ }(ErrorResponse));
283
+ export { ServiceUnavailableException };
284
+ /**
285
+ * Represents a 504 Gateway Timeout Error.
286
+ * Returned when the server acting as a gateway times out waiting for a response.
287
+ */
288
+ var GatewayTimeoutException = /** @class */ (function (_super) {
289
+ __extends(GatewayTimeoutException, _super);
290
+ /**
291
+ * @param message - Optional custom message. Defaults to "Gateway Timeout".
292
+ */
293
+ function GatewayTimeoutException(message) {
294
+ if (message === void 0) { message = 'Gateway Timeout'; }
295
+ var _this = _super.call(this, message) || this;
296
+ _this.status = HttpStatusCodes.GATEWAY_TIMEOUT;
297
+ return _this;
298
+ }
299
+ return GatewayTimeoutException;
300
+ }(ErrorResponse));
301
+ export { GatewayTimeoutException };
302
+ /**
303
+ * Represents a 422 Unprocessable Entity Error.
304
+ * Used when the server understands the content type but cannot process the contained instructions.
305
+ */
306
+ var UnprocessableEntityException = /** @class */ (function (_super) {
307
+ __extends(UnprocessableEntityException, _super);
308
+ /**
309
+ * @param message - Optional custom message. Defaults to "Unprocessable Entity".
310
+ * @param details - Optional validation details or additional error context.
311
+ */
312
+ function UnprocessableEntityException(message, details) {
313
+ if (message === void 0) { message = 'Unprocessable Entity'; }
314
+ var _this = _super.call(this, message) || this;
315
+ _this.details = details;
316
+ _this.status = HttpStatusCodes.UNPROCESSABLE_ENTITY;
317
+ return _this;
318
+ }
319
+ return UnprocessableEntityException;
320
+ }(ErrorResponse));
321
+ export { UnprocessableEntityException };
322
+ /**
323
+ * Represents a 405 Method Not Allowed Error.
324
+ * Used when the request method is not supported for the requested resource.
325
+ */
326
+ var MethodNotAllowedException = /** @class */ (function (_super) {
327
+ __extends(MethodNotAllowedException, _super);
328
+ /**
329
+ * @param message - Optional custom message. Defaults to "Method Not Allowed".
330
+ * @param allowedMethods - Optional array of allowed HTTP methods.
331
+ */
332
+ function MethodNotAllowedException(message, allowedMethods) {
333
+ if (message === void 0) { message = 'Method Not Allowed'; }
334
+ var _this = _super.call(this, message) || this;
335
+ _this.allowedMethods = allowedMethods;
336
+ _this.status = HttpStatusCodes.METHOD_NOT_ALLOWED;
337
+ return _this;
338
+ }
339
+ return MethodNotAllowedException;
340
+ }(ErrorResponse));
341
+ export { MethodNotAllowedException };
342
+ /**
343
+ * Represents a 406 Not Acceptable Error.
344
+ * Used when the server cannot produce a response matching the client's accepted content types.
345
+ */
346
+ var NotAcceptableException = /** @class */ (function (_super) {
347
+ __extends(NotAcceptableException, _super);
348
+ /**
349
+ * @param message - Optional custom message. Defaults to "Not Acceptable".
350
+ */
351
+ function NotAcceptableException(message) {
352
+ if (message === void 0) { message = 'Not Acceptable'; }
353
+ var _this = _super.call(this, message) || this;
354
+ _this.status = HttpStatusCodes.NOT_ACCEPTABLE;
355
+ return _this;
356
+ }
357
+ return NotAcceptableException;
358
+ }(ErrorResponse));
359
+ export { NotAcceptableException };
360
+ /**
361
+ * Represents a 408 Request Timeout Error.
362
+ * Used when the server times out waiting for the client to send a request.
363
+ */
364
+ var RequestTimeoutException = /** @class */ (function (_super) {
365
+ __extends(RequestTimeoutException, _super);
366
+ /**
367
+ * @param message - Optional custom message. Defaults to "Request Timeout".
368
+ */
369
+ function RequestTimeoutException(message) {
370
+ if (message === void 0) { message = 'Request Timeout'; }
371
+ var _this = _super.call(this, message) || this;
372
+ _this.status = HttpStatusCodes.REQUEST_TIMEOUT;
373
+ return _this;
374
+ }
375
+ return RequestTimeoutException;
376
+ }(ErrorResponse));
377
+ export { RequestTimeoutException };
378
+ /**
379
+ * Represents a 415 Unsupported Media Type Error.
380
+ * Used when the request's Content-Type is not supported.
381
+ */
382
+ var UnsupportedMediaTypeException = /** @class */ (function (_super) {
383
+ __extends(UnsupportedMediaTypeException, _super);
384
+ /**
385
+ * @param message - Optional custom message. Defaults to "Unsupported Media Type".
386
+ */
387
+ function UnsupportedMediaTypeException(message) {
388
+ if (message === void 0) { message = 'Unsupported Media Type'; }
389
+ var _this = _super.call(this, message) || this;
390
+ _this.status = HttpStatusCodes.UNSUPPORTED_MEDIA_TYPE;
391
+ return _this;
392
+ }
393
+ return UnsupportedMediaTypeException;
394
+ }(ErrorResponse));
395
+ export { UnsupportedMediaTypeException };
396
+ /**
397
+ * Represents a 413 Payload Too Large Error.
398
+ * Used when the request body exceeds server limits.
399
+ */
400
+ var PayloadTooLargeException = /** @class */ (function (_super) {
401
+ __extends(PayloadTooLargeException, _super);
402
+ /**
403
+ * @param message - Optional custom message. Defaults to "Payload Too Large".
404
+ */
405
+ function PayloadTooLargeException(message) {
406
+ if (message === void 0) { message = 'Payload Too Large'; }
407
+ var _this = _super.call(this, message) || this;
408
+ _this.status = HttpStatusCodes.PAYLOAD_TOO_LARGE;
409
+ return _this;
410
+ }
411
+ return PayloadTooLargeException;
412
+ }(ErrorResponse));
413
+ export { PayloadTooLargeException };
414
+ /**
415
+ * Represents a 507 Insufficient Storage Error.
416
+ * Used when the server has insufficient storage to complete the request.
417
+ */
418
+ var InsufficientStorageException = /** @class */ (function (_super) {
419
+ __extends(InsufficientStorageException, _super);
420
+ /**
421
+ * @param message - Optional custom message. Defaults to "Insufficient Storage".
422
+ */
423
+ function InsufficientStorageException(message) {
424
+ if (message === void 0) { message = 'Insufficient Storage'; }
425
+ var _this = _super.call(this, message) || this;
426
+ _this.status = HttpStatusCodes.INSUFFICIENT_STORAGE;
427
+ return _this;
428
+ }
429
+ return InsufficientStorageException;
430
+ }(ErrorResponse));
431
+ export { InsufficientStorageException };
432
+ /**
433
+ * Checks if an error is an instance of HttpError or its subclasses.
434
+ *
435
+ * @param error - The error to check.
436
+ * @returns True if the error is an HttpError, false otherwise.
437
+ */
438
+ export function isHttpError(error) {
439
+ return error instanceof ErrorResponse;
440
+ }
441
+ /**
442
+ * Creates an HTTP error with the specified status code and message.
443
+ * Factory function for creating appropriate HTTP error instances.
444
+ *
445
+ * @param status - HTTP status code.
446
+ * @param message - Optional custom error message.
447
+ * @returns An instance of the appropriate HTTP error class.
448
+ */
449
+ export function createHttpError(status, message) {
450
+ switch (status) {
451
+ case HttpStatusCodes.BAD_REQUEST:
452
+ return new BadRequestException(message);
453
+ case HttpStatusCodes.UNAUTHORIZED:
454
+ return new UnauthorizedException(message);
455
+ case HttpStatusCodes.FORBIDDEN:
456
+ return new ForbiddenException(message);
457
+ case HttpStatusCodes.NOT_FOUND:
458
+ return new NotFoundException(message);
459
+ case HttpStatusCodes.METHOD_NOT_ALLOWED:
460
+ return new MethodNotAllowedException(message);
461
+ case HttpStatusCodes.NOT_ACCEPTABLE:
462
+ return new NotAcceptableException(message);
463
+ case HttpStatusCodes.REQUEST_TIMEOUT:
464
+ return new RequestTimeoutException(message);
465
+ case HttpStatusCodes.CONFLICT:
466
+ return new ConflictException(message);
467
+ case HttpStatusCodes.GONE:
468
+ return new HttpError(HttpStatusCodes.GONE, message || 'Gone');
469
+ case HttpStatusCodes.PAYLOAD_TOO_LARGE:
470
+ return new PayloadTooLargeException(message);
471
+ case HttpStatusCodes.UNSUPPORTED_MEDIA_TYPE:
472
+ return new UnsupportedMediaTypeException(message);
473
+ case HttpStatusCodes.UNPROCESSABLE_ENTITY:
474
+ return new UnprocessableEntityException(message);
475
+ case HttpStatusCodes.TOO_MANY_REQUESTS:
476
+ return new TooManyRequestsException(message);
477
+ case HttpStatusCodes.INTERNAL_SERVER_ERROR:
478
+ return new InternalServerErrorException(message);
479
+ case HttpStatusCodes.BAD_GATEWAY:
480
+ return new BadGatewayException(message);
481
+ case HttpStatusCodes.SERVICE_UNAVAILABLE:
482
+ return new ServiceUnavailableException(message);
483
+ case HttpStatusCodes.GATEWAY_TIMEOUT:
484
+ return new GatewayTimeoutException(message);
485
+ case HttpStatusCodes.INSUFFICIENT_STORAGE:
486
+ return new InsufficientStorageException(message);
487
+ default:
488
+ return new HttpError(status, message || "HTTP Error ".concat(status));
489
+ }
490
+ }
491
+ /**
492
+ * Type guard to check if an object has specific error properties.
493
+ *
494
+ * @param error - The object to check.
495
+ * @returns True if object has error-like structure.
496
+ */
497
+ export function hasErrorShape(error) {
498
+ return (typeof error === 'object' && error !== null && 'message' in error && typeof error.message === 'string');
499
+ }
500
+ /**
501
+ * Safely extracts message from any error type.
502
+ *
503
+ * @param error - Any error object or value.
504
+ * @returns A string error message.
505
+ */
506
+ export function getErrorMessage(error) {
507
+ if (typeof error === 'string') {
508
+ return error;
509
+ }
510
+ if (error instanceof Error) {
511
+ return error.message;
512
+ }
513
+ if (hasErrorShape(error)) {
514
+ return error.message;
515
+ }
516
+ return 'Unknown error occurred';
517
+ }
518
+ /**
519
+ * Wraps a function and transforms any errors into HTTP errors.
520
+ * Useful for API handlers to ensure consistent error responses.
521
+ *
522
+ * @param handler - The async function to wrap.
523
+ * @returns A function that always returns or throws an HTTP error.
524
+ */
525
+ export function withErrorHandling(handler) {
526
+ var _this = this;
527
+ return function () {
528
+ var args = [];
529
+ for (var _i = 0; _i < arguments.length; _i++) {
530
+ args[_i] = arguments[_i];
531
+ }
532
+ return __awaiter(_this, void 0, void 0, function () {
533
+ var err_1, status_1;
534
+ return __generator(this, function (_a) {
535
+ switch (_a.label) {
536
+ case 0:
537
+ _a.trys.push([0, 2, , 3]);
538
+ return [4 /*yield*/, handler.apply(void 0, __spreadArray([], __read(args), false))];
539
+ case 1: return [2 /*return*/, _a.sent()];
540
+ case 2:
541
+ err_1 = _a.sent();
542
+ if (isHttpError(err_1)) {
543
+ throw err_1;
544
+ }
545
+ // Log the original error (consider using a proper logger)
546
+ getLogger().error({ err: err_1 }, 'Caught error in handler');
547
+ status_1 = HttpStatusCodes.INTERNAL_SERVER_ERROR;
548
+ if (hasErrorShape(err_1) && typeof err_1.status === 'number') {
549
+ status_1 = err_1.status;
550
+ }
551
+ // Create appropriate HTTP error
552
+ throw createHttpError(status_1, getErrorMessage(err_1));
553
+ case 3: return [2 /*return*/];
554
+ }
555
+ });
556
+ });
557
+ };
558
+ }
559
+ //# sourceMappingURL=exception.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exception.utils.js","sourceRoot":"","sources":["../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;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAC/B,OAAU;IADZ,iBAwBC;IArBC,OAAO;QAAO,cAAsB;aAAtB,UAAsB,EAAtB,qBAAsB,EAAtB,IAAsB;YAAtB,yBAAsB;;;;;;;;wBAEzB,qBAAM,OAAO,wCAAI,IAAI,YAAC;4BAA7B,sBAAO,SAAsB,EAAC;;;wBAE9B,IAAI,WAAW,CAAC,KAAG,CAAC,EAAE,CAAC;4BACrB,MAAM,KAAG,CAAC;wBACZ,CAAC;wBAED,0DAA0D;wBAC1D,SAAS,EAAE,CAAC,KAAK,CAAC,EAAE,GAAG,OAAA,EAAE,EAAE,yBAAyB,CAAC,CAAC;wBAGlD,WAAS,eAAe,CAAC,qBAAqB,CAAC;wBACnD,IAAI,aAAa,CAAC,KAAG,CAAC,IAAI,OAAO,KAAG,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;4BACzD,QAAM,GAAG,KAAG,CAAC,MAAM,CAAC;wBACtB,CAAC;wBAED,gCAAgC;wBAChC,MAAM,eAAe,CAAC,QAAM,EAAE,eAAe,CAAC,KAAG,CAAC,CAAC,CAAC;;;;;KAEvD,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"]}