@navios/core 1.1.0 → 2.0.0-alpha.0

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 (241) hide show
  1. package/CHANGELOG.md +53 -11
  2. package/README.md +67 -220
  3. package/lib/async-context-6pdlnNLA.d.mts +237 -0
  4. package/lib/async-context-6pdlnNLA.d.mts.map +1 -0
  5. package/lib/async-context-Dqk7pE-D.d.cts +237 -0
  6. package/lib/async-context-Dqk7pE-D.d.cts.map +1 -0
  7. package/lib/attribute-factory-B3VuYnp7.d.cts +70 -0
  8. package/lib/attribute-factory-B3VuYnp7.d.cts.map +1 -0
  9. package/lib/attribute-factory-mKOXoVnV.d.mts +70 -0
  10. package/lib/attribute-factory-mKOXoVnV.d.mts.map +1 -0
  11. package/lib/attribute-value-CjX9ZkLq.cjs +172 -0
  12. package/lib/attribute-value-CjX9ZkLq.cjs.map +1 -0
  13. package/lib/attribute-value-DMEA255r.mjs +119 -0
  14. package/lib/attribute-value-DMEA255r.mjs.map +1 -0
  15. package/lib/basic-execution-context-CeGuhMOz.mjs +246 -0
  16. package/lib/basic-execution-context-CeGuhMOz.mjs.map +1 -0
  17. package/lib/basic-execution-context-DSk5MNtc.cjs +281 -0
  18. package/lib/basic-execution-context-DSk5MNtc.cjs.map +1 -0
  19. package/lib/execution-context-BPD3FeFb.d.mts +71 -0
  20. package/lib/execution-context-BPD3FeFb.d.mts.map +1 -0
  21. package/lib/execution-context-BTJdHhbf.d.cts +71 -0
  22. package/lib/execution-context-BTJdHhbf.d.cts.map +1 -0
  23. package/lib/execution-context-token-BXUKB2hf.cjs +112 -0
  24. package/lib/execution-context-token-BXUKB2hf.cjs.map +1 -0
  25. package/lib/execution-context-token-CrXmTvk2.mjs +77 -0
  26. package/lib/execution-context-token-CrXmTvk2.mjs.map +1 -0
  27. package/lib/index.cjs +1687 -4424
  28. package/lib/index.cjs.map +1 -1
  29. package/lib/index.d.cts +838 -3
  30. package/lib/index.d.cts.map +1 -0
  31. package/lib/index.d.mts +838 -3
  32. package/lib/index.d.mts.map +1 -0
  33. package/lib/index.mjs +1573 -4219
  34. package/lib/index.mjs.map +1 -1
  35. package/lib/legacy-compat/index.cjs +72 -371
  36. package/lib/legacy-compat/index.cjs.map +1 -1
  37. package/lib/legacy-compat/index.d.cts +42 -382
  38. package/lib/legacy-compat/index.d.cts.map +1 -1
  39. package/lib/legacy-compat/index.d.mts +41 -382
  40. package/lib/legacy-compat/index.d.mts.map +1 -1
  41. package/lib/legacy-compat/index.mjs +51 -345
  42. package/lib/legacy-compat/index.mjs.map +1 -1
  43. package/lib/module-Bha7GER_.mjs +135 -0
  44. package/lib/module-Bha7GER_.mjs.map +1 -0
  45. package/lib/module-DZewk_2r.cjs +164 -0
  46. package/lib/module-DZewk_2r.cjs.map +1 -0
  47. package/lib/module-graph-DCP9MHG0.cjs +147 -0
  48. package/lib/module-graph-DCP9MHG0.cjs.map +1 -0
  49. package/lib/module-graph-xvVEykFM.mjs +142 -0
  50. package/lib/module-graph-xvVEykFM.mjs.map +1 -0
  51. package/lib/module-metadata-C8S92seK.cjs +95 -0
  52. package/lib/module-metadata-C8S92seK.cjs.map +1 -0
  53. package/lib/module-metadata-k3RTt20x.mjs +66 -0
  54. package/lib/module-metadata-k3RTt20x.mjs.map +1 -0
  55. package/lib/module-options-Dmse0gii.d.mts +51 -0
  56. package/lib/module-options-Dmse0gii.d.mts.map +1 -0
  57. package/lib/module-options-IuDO-p8u.d.cts +51 -0
  58. package/lib/module-options-IuDO-p8u.d.cts.map +1 -0
  59. package/lib/testing/index.cjs +96 -414
  60. package/lib/testing/index.cjs.map +1 -1
  61. package/lib/testing/index.d.cts +25 -385
  62. package/lib/testing/index.d.cts.map +1 -1
  63. package/lib/testing/index.d.mts +24 -385
  64. package/lib/testing/index.d.mts.map +1 -1
  65. package/lib/testing/index.mjs +94 -408
  66. package/lib/testing/index.mjs.map +1 -1
  67. package/lib/transport.cjs +25 -0
  68. package/lib/transport.d.cts +190 -0
  69. package/lib/transport.d.cts.map +1 -0
  70. package/lib/transport.d.mts +190 -0
  71. package/lib/transport.d.mts.map +1 -0
  72. package/lib/transport.mjs +7 -0
  73. package/package.json +37 -17
  74. package/docs/README.md +0 -316
  75. package/docs/adapters.md +0 -308
  76. package/docs/application-setup.md +0 -524
  77. package/docs/attributes.md +0 -689
  78. package/docs/controllers.md +0 -373
  79. package/docs/endpoints.md +0 -444
  80. package/docs/exceptions.md +0 -352
  81. package/docs/guards.md +0 -550
  82. package/docs/legacy-compat.md +0 -356
  83. package/docs/modules.md +0 -377
  84. package/docs/quick-start.md +0 -290
  85. package/docs/services.md +0 -427
  86. package/docs/testing.md +0 -827
  87. package/lib/index-3LcTrbxz.d.mts +0 -3804
  88. package/lib/index-3LcTrbxz.d.mts.map +0 -1
  89. package/lib/index-B14SekVb.d.cts +0 -3804
  90. package/lib/index-B14SekVb.d.cts.map +0 -1
  91. package/lib/navios.factory-CUrO_p6K.cjs +0 -4538
  92. package/lib/navios.factory-CUrO_p6K.cjs.map +0 -1
  93. package/lib/navios.factory-DjUOOVVL.mjs +0 -4151
  94. package/lib/navios.factory-DjUOOVVL.mjs.map +0 -1
  95. package/lib/tokens-BEuBMGGX.cjs +0 -193
  96. package/lib/tokens-BEuBMGGX.cjs.map +0 -1
  97. package/lib/tokens-COyNGV1I.mjs +0 -97
  98. package/lib/tokens-COyNGV1I.mjs.map +0 -1
  99. package/lib/use-guards.decorator-DLmRl2CV.mjs +0 -336
  100. package/lib/use-guards.decorator-DLmRl2CV.mjs.map +0 -1
  101. package/lib/use-guards.decorator-DhumFTk3.cjs +0 -444
  102. package/lib/use-guards.decorator-DhumFTk3.cjs.map +0 -1
  103. package/project.json +0 -66
  104. package/src/__tests__/attribute.factory.spec.mts +0 -300
  105. package/src/__tests__/config.service.spec.mts +0 -43
  106. package/src/__tests__/console-logger.service.spec.mts +0 -312
  107. package/src/__tests__/controller-resolver.spec.mts +0 -229
  108. package/src/__tests__/controller.spec.mts +0 -58
  109. package/src/__tests__/guard-runner.service.spec.mts +0 -399
  110. package/src/__tests__/logger.service.spec.mts +0 -147
  111. package/src/__tests__/responders.spec.mts +0 -340
  112. package/src/__tests__/testing-module.spec.mts +0 -459
  113. package/src/__tests__/unit-testing-module.spec.mts +0 -424
  114. package/src/attribute.factory.mts +0 -325
  115. package/src/config/config-service.interface.mts +0 -47
  116. package/src/config/config.provider.mts +0 -69
  117. package/src/config/config.service.mts +0 -176
  118. package/src/config/index.mts +0 -5
  119. package/src/config/types.mts +0 -58
  120. package/src/config/utils/helpers.mts +0 -23
  121. package/src/config/utils/index.mts +0 -1
  122. package/src/decorators/controller.decorator.mts +0 -81
  123. package/src/decorators/endpoint.decorator.mts +0 -181
  124. package/src/decorators/header.decorator.mts +0 -38
  125. package/src/decorators/http-code.decorator.mts +0 -38
  126. package/src/decorators/index.mts +0 -8
  127. package/src/decorators/module.decorator.mts +0 -106
  128. package/src/decorators/multipart.decorator.mts +0 -169
  129. package/src/decorators/stream.decorator.mts +0 -155
  130. package/src/decorators/use-guards.decorator.mts +0 -73
  131. package/src/exceptions/bad-request.exception.mts +0 -28
  132. package/src/exceptions/conflict.exception.mts +0 -31
  133. package/src/exceptions/forbidden.exception.mts +0 -30
  134. package/src/exceptions/http.exception.mts +0 -33
  135. package/src/exceptions/index.mts +0 -7
  136. package/src/exceptions/internal-server-error.exception.mts +0 -33
  137. package/src/exceptions/not-found.exception.mts +0 -33
  138. package/src/exceptions/unauthorized.exception.mts +0 -30
  139. package/src/factories/adapter.factory.mts +0 -20
  140. package/src/factories/endpoint-adapter.factory.mts +0 -21
  141. package/src/factories/http-adapter.factory.mts +0 -20
  142. package/src/factories/index.mts +0 -8
  143. package/src/factories/multipart-adapter.factory.mts +0 -21
  144. package/src/factories/reply.factory.mts +0 -21
  145. package/src/factories/request.factory.mts +0 -21
  146. package/src/factories/stream-adapter.factory.mts +0 -20
  147. package/src/factories/xml-stream-adapter.factory.mts +0 -20
  148. package/src/index.mts +0 -16
  149. package/src/interfaces/abstract-adapter.interface.mts +0 -32
  150. package/src/interfaces/abstract-execution-context.inteface.mts +0 -48
  151. package/src/interfaces/abstract-http-adapter.interface.mts +0 -79
  152. package/src/interfaces/abstract-http-cors-options.interface.mts +0 -59
  153. package/src/interfaces/abstract-http-handler-adapter.interface.mts +0 -127
  154. package/src/interfaces/abstract-http-listen-options.interface.mts +0 -4
  155. package/src/interfaces/adapter-environment.interface.mts +0 -74
  156. package/src/interfaces/can-activate.mts +0 -38
  157. package/src/interfaces/http-header.mts +0 -18
  158. package/src/interfaces/index.mts +0 -14
  159. package/src/interfaces/navios-module.mts +0 -28
  160. package/src/interfaces/plugin-context.mts +0 -104
  161. package/src/interfaces/plugin-stage.mts +0 -62
  162. package/src/interfaces/plugin.interface.mts +0 -119
  163. package/src/interfaces/staged-plugin.interface.mts +0 -209
  164. package/src/legacy-compat/__type-tests__/legacy-decorators.spec-d.mts +0 -521
  165. package/src/legacy-compat/__type-tests__/tsconfig.json +0 -15
  166. package/src/legacy-compat/attribute.factory.mts +0 -351
  167. package/src/legacy-compat/decorators/controller.decorator.mts +0 -31
  168. package/src/legacy-compat/decorators/endpoint.decorator.mts +0 -73
  169. package/src/legacy-compat/decorators/header.decorator.mts +0 -43
  170. package/src/legacy-compat/decorators/http-code.decorator.mts +0 -39
  171. package/src/legacy-compat/decorators/index.mts +0 -11
  172. package/src/legacy-compat/decorators/module.decorator.mts +0 -37
  173. package/src/legacy-compat/decorators/multipart.decorator.mts +0 -72
  174. package/src/legacy-compat/decorators/stream.decorator.mts +0 -89
  175. package/src/legacy-compat/decorators/use-guards.decorator.mts +0 -80
  176. package/src/legacy-compat/index.mts +0 -57
  177. package/src/logger/README.md +0 -3
  178. package/src/logger/console-logger.service.mts +0 -714
  179. package/src/logger/index.mts +0 -6
  180. package/src/logger/log-levels.mts +0 -21
  181. package/src/logger/logger-service.interface.mts +0 -42
  182. package/src/logger/logger.service.mts +0 -113
  183. package/src/logger/logger.tokens.mts +0 -44
  184. package/src/logger/utils/cli-colors.util.mts +0 -17
  185. package/src/logger/utils/filter-log-levelts.util.mts +0 -29
  186. package/src/logger/utils/index.mts +0 -5
  187. package/src/logger/utils/is-log-level-enabled.mts +0 -33
  188. package/src/logger/utils/is-log-level.util.mts +0 -10
  189. package/src/logger/utils/shared.utils.mts +0 -51
  190. package/src/metadata/controller.metadata.mts +0 -79
  191. package/src/metadata/handler.metadata.mts +0 -80
  192. package/src/metadata/index.mts +0 -4
  193. package/src/metadata/module.metadata.mts +0 -116
  194. package/src/metadata/navios-managed.metadata.mts +0 -42
  195. package/src/navios.application.mts +0 -678
  196. package/src/navios.environment.mts +0 -42
  197. package/src/navios.factory.mts +0 -158
  198. package/src/responders/enums/framework-error.enum.mts +0 -38
  199. package/src/responders/enums/index.mts +0 -1
  200. package/src/responders/index.mts +0 -4
  201. package/src/responders/interfaces/error-responder.interface.mts +0 -42
  202. package/src/responders/interfaces/error-response.interface.mts +0 -22
  203. package/src/responders/interfaces/index.mts +0 -3
  204. package/src/responders/interfaces/problem-details.interface.mts +0 -34
  205. package/src/responders/services/error-response-producer.service.mts +0 -143
  206. package/src/responders/services/forbidden-responder.service.mts +0 -77
  207. package/src/responders/services/index.mts +0 -5
  208. package/src/responders/services/internal-server-error-responder.service.mts +0 -57
  209. package/src/responders/services/not-found-responder.service.mts +0 -76
  210. package/src/responders/services/validation-error-responder.service.mts +0 -78
  211. package/src/responders/tokens/index.mts +0 -1
  212. package/src/responders/tokens/responder.tokens.mts +0 -84
  213. package/src/services/abstract-handler-adapter.service.mts +0 -366
  214. package/src/services/guard-runner.service.mts +0 -152
  215. package/src/services/index.mts +0 -4
  216. package/src/services/instance-resolver.service.mts +0 -177
  217. package/src/services/module-loader.service.mts +0 -255
  218. package/src/stores/index.mts +0 -1
  219. package/src/stores/request-id.store.mts +0 -85
  220. package/src/testing/index.mts +0 -3
  221. package/src/testing/testing-module.mts +0 -393
  222. package/src/testing/unit-testing-module.mts +0 -298
  223. package/src/tokens/adapter.token.mts +0 -6
  224. package/src/tokens/endpoint-adapter.token.mts +0 -8
  225. package/src/tokens/execution-context.token.mts +0 -9
  226. package/src/tokens/http-adapter.token.mts +0 -8
  227. package/src/tokens/index.mts +0 -10
  228. package/src/tokens/multipart-adapter.token.mts +0 -8
  229. package/src/tokens/navios-options.token.mts +0 -6
  230. package/src/tokens/reply.token.mts +0 -3
  231. package/src/tokens/request.token.mts +0 -3
  232. package/src/tokens/stream-adapter.token.mts +0 -8
  233. package/src/tokens/xml-stream-adapter.token.mts +0 -8
  234. package/src/utils/adapter-supports.util.mts +0 -47
  235. package/src/utils/define-plugin.mts +0 -251
  236. package/src/utils/index.mts +0 -2
  237. package/tsconfig.json +0 -21
  238. package/tsconfig.lib.json +0 -8
  239. package/tsconfig.spec.json +0 -15
  240. package/tsdown.config.mts +0 -35
  241. package/vitest.config.mts +0 -15
@@ -1,352 +0,0 @@
1
- # Exception Handling
2
-
3
- Navios provides a comprehensive exception handling system that allows you to throw HTTP exceptions and handle errors in a consistent manner across your application.
4
-
5
- ## Built-in HTTP Exceptions
6
-
7
- Navios includes several built-in HTTP exception classes that correspond to common HTTP status codes:
8
-
9
- ### BadRequestException (400)
10
-
11
- ### UnauthorizedException (401)
12
-
13
- ### ForbiddenException (403)
14
-
15
- ### NotFoundException (404)
16
-
17
- ### ConflictException (409)
18
-
19
- ### InternalServerErrorException (500)
20
-
21
- ## Base HttpException
22
-
23
- All HTTP exceptions extend the base `HttpException` class:
24
-
25
- ```typescript
26
- import { HttpException } from '@navios/core'
27
-
28
- // Create custom exception
29
- export class CustomException extends HttpException {
30
- constructor(message: string) {
31
- super(message, 418) // I'm a teapot
32
- }
33
- }
34
-
35
- // Or throw HttpException directly
36
- @Controller()
37
- export class UserController {
38
- @Endpoint(getUserByIdEndpoint)
39
- async getUserById({ params }: { params: { id: string } }) {
40
- if (!this.isValidId(params.id)) {
41
- throw new HttpException('Invalid user ID format', 422)
42
- }
43
-
44
- return this.userService.findById(params.id)
45
- }
46
- }
47
- ```
48
-
49
- ## Exception with Additional Data
50
-
51
- You can include additional data in exceptions:
52
-
53
- ```typescript
54
- import { BadRequestException } from '@navios/core'
55
-
56
- @Controller()
57
- export class UserController {
58
- @Endpoint(createUserEndpoint)
59
- async createUser({ body }: { body: CreateUserDto }) {
60
- const validationErrors = await this.validateUser(body)
61
-
62
- if (validationErrors.length > 0) {
63
- throw new BadRequestException({
64
- message: 'Validation failed',
65
- errors: validationErrors,
66
- timestamp: new Date().toISOString(),
67
- })
68
- }
69
-
70
- return this.userService.create(body)
71
- }
72
-
73
- private async validateUser(user: CreateUserDto) {
74
- const errors: string[] = []
75
-
76
- if (!user.email) {
77
- errors.push('Email is required')
78
- } else if (!this.isValidEmail(user.email)) {
79
- errors.push('Invalid email format')
80
- }
81
-
82
- if (!user.password || user.password.length < 8) {
83
- errors.push('Password must be at least 8 characters')
84
- }
85
-
86
- return errors
87
- }
88
- }
89
- ```
90
-
91
- ## Custom Exceptions
92
-
93
- Create domain-specific exceptions by extending HTTP exceptions:
94
-
95
- ```typescript
96
- import {
97
- BadRequestException,
98
- ConflictException,
99
- NotFoundException,
100
- } from '@navios/core'
101
-
102
- // Domain-specific exceptions
103
- export class UserNotFoundException extends NotFoundException {
104
- constructor(userId: string) {
105
- super(`User with ID ${userId} not found`)
106
- }
107
- }
108
-
109
- export class InvalidEmailException extends BadRequestException {
110
- constructor(email: string) {
111
- super({
112
- message: 'Invalid email address',
113
- email,
114
- code: 'INVALID_EMAIL',
115
- })
116
- }
117
- }
118
-
119
- export class EmailAlreadyExistsException extends ConflictException {
120
- constructor(email: string) {
121
- super({
122
- message: 'Email address already exists',
123
- email,
124
- code: 'EMAIL_EXISTS',
125
- })
126
- }
127
- }
128
- ```
129
-
130
- ## Async Exception Handling
131
-
132
- Handle exceptions in async operations:
133
-
134
- ```typescript
135
- @Controller()
136
- export class UserController {
137
- private logger = inject(Logger, { context: 'UserController' })
138
-
139
- @Endpoint(sendEmailEndpoint)
140
- async sendEmail({ params }: { params: { id: string } }) {
141
- try {
142
- const user = await this.userService.findById(params.id)
143
-
144
- if (!user) {
145
- throw new NotFoundException(`User with ID ${params.id} not found`)
146
- }
147
-
148
- await this.emailService.sendWelcomeEmail(user.email)
149
-
150
- return { message: 'Email sent successfully' }
151
- } catch (error) {
152
- if (error instanceof HttpException) {
153
- throw error // Re-throw HTTP exceptions
154
- }
155
-
156
- // Log unexpected errors
157
- this.logger.error('Failed to send email', {
158
- userId: params.id,
159
- error: error.message,
160
- stack: error.stack,
161
- })
162
-
163
- throw new InternalServerErrorException('Failed to send email')
164
- }
165
- }
166
- }
167
- ```
168
-
169
- ## Exception Response Format
170
-
171
- ### HttpException Response Format
172
-
173
- `HttpException` and its subclasses (like `NotFoundException`, `BadRequestException`, etc.) maintain backward compatibility and return the original format:
174
-
175
- ```json
176
- {
177
- "statusCode": 404,
178
- "message": "User with ID 123 not found",
179
- "timestamp": "2023-10-01T12:00:00.000Z",
180
- "path": "/users/123"
181
- }
182
- ```
183
-
184
- For exceptions with additional data:
185
-
186
- ```json
187
- {
188
- "statusCode": 400,
189
- "message": "Validation failed",
190
- "errors": [
191
- {
192
- "field": "email",
193
- "message": "Invalid email format",
194
- "code": "INVALID_EMAIL"
195
- }
196
- ],
197
- "timestamp": "2023-10-01T12:00:00.000Z",
198
- "path": "/users"
199
- }
200
- ```
201
-
202
- ### RFC 7807 Problem Details Format
203
-
204
- Framework-level errors (validation errors, guard rejections, not found routes, unhandled errors) use **RFC 7807 Problem Details** format for standardized, machine-readable error responses:
205
-
206
- ```json
207
- {
208
- "type": "about:blank",
209
- "title": "Not Found",
210
- "status": 404,
211
- "detail": "Route [GET] /api/users/999 not found"
212
- }
213
- ```
214
-
215
- Validation errors include structured error details:
216
-
217
- ```json
218
- {
219
- "type": "about:blank",
220
- "title": "Validation Error",
221
- "status": 400,
222
- "detail": "Request validation failed",
223
- "errors": {
224
- "email": {
225
- "code": "invalid_string",
226
- "validation": "email",
227
- "message": "Invalid email",
228
- "path": ["email"]
229
- }
230
- }
231
- }
232
- ```
233
-
234
- All Problem Details responses include the `Content-Type: application/problem+json` header. For more information on customizing error responders, see the [Error Handling Guide](../../../apps/docs/docs/server/guides/error-handling.md).
235
-
236
- ## Best Practices
237
-
238
- ### 1. Use Specific Exceptions
239
-
240
- Use the most specific exception type for better error handling:
241
-
242
- ```typescript
243
- // ✅ Good - Specific exception
244
- if (!user) {
245
- throw new NotFoundException(`User with ID ${id} not found`)
246
- }
247
-
248
- // ❌ Avoid - Generic exception
249
- if (!user) {
250
- throw new HttpException('User not found', 404)
251
- }
252
- ```
253
-
254
- ### 2. Include Context
255
-
256
- Provide helpful context in exception messages:
257
-
258
- ```typescript
259
- // ✅ Good - Includes context
260
- throw new BadRequestException({
261
- message: 'Invalid user data',
262
- field: 'email',
263
- value: email,
264
- reason: 'Email format is invalid',
265
- })
266
-
267
- // ❌ Avoid - Vague message
268
- throw new BadRequestException('Invalid data')
269
- ```
270
-
271
- ### 3. Log Appropriately
272
-
273
- Log exceptions at appropriate levels:
274
-
275
- ```typescript
276
- @Controller()
277
- export class UserController {
278
- private logger = inject(Logger, { context: 'UserController' })
279
-
280
- async getUser(id: string) {
281
- try {
282
- return await this.userService.findById(id)
283
- } catch (error) {
284
- if (error instanceof NotFoundException) {
285
- // Don't log client errors as errors
286
- this.logger.debug(`User not found: ${id}`)
287
- throw error
288
- }
289
-
290
- // Log server errors
291
- this.logger.error('Failed to get user', {
292
- userId: id,
293
- error: error.message,
294
- stack: error.stack,
295
- })
296
-
297
- throw new InternalServerErrorException('Failed to retrieve user')
298
- }
299
- }
300
- }
301
- ```
302
-
303
- ### 4. Don't Expose Internal Details
304
-
305
- Don't expose sensitive information in exception messages:
306
-
307
- ```typescript
308
- // ✅ Good - Safe message
309
- throw new InternalServerErrorException('Database connection failed')
310
-
311
- // ❌ Avoid - Exposes sensitive info
312
- throw new InternalServerErrorException(
313
- `Database connection failed: ${databaseUrl} with credentials ${username}:${password}`,
314
- )
315
- ```
316
-
317
- ### 5. Create Domain-Specific Exceptions
318
-
319
- Create exceptions that match your domain:
320
-
321
- ```typescript
322
- // User domain exceptions
323
- export class UserNotFoundException extends NotFoundException {
324
- constructor(userId: string) {
325
- super(`User with ID ${userId} not found`)
326
- }
327
- }
328
-
329
- export class UserEmailAlreadyExistsException extends ConflictException {
330
- constructor(email: string) {
331
- super(`User with email ${email} already exists`)
332
- }
333
- }
334
-
335
- // Order domain exceptions
336
- export class OrderNotFoundException extends NotFoundException {
337
- constructor(orderId: string) {
338
- super(`Order with ID ${orderId} not found`)
339
- }
340
- }
341
-
342
- export class InsufficientInventoryException extends ConflictException {
343
- constructor(productId: string, requested: number, available: number) {
344
- super({
345
- message: 'Insufficient inventory',
346
- productId,
347
- requested,
348
- available,
349
- })
350
- }
351
- }
352
- ```