nexo-schemas 0.0.16__py3-none-any.whl

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 (69) hide show
  1. nexo/schemas/__init__.py +0 -0
  2. nexo/schemas/application.py +292 -0
  3. nexo/schemas/connection.py +134 -0
  4. nexo/schemas/data.py +27 -0
  5. nexo/schemas/document.py +237 -0
  6. nexo/schemas/error/__init__.py +476 -0
  7. nexo/schemas/error/constants.py +50 -0
  8. nexo/schemas/error/descriptor.py +354 -0
  9. nexo/schemas/error/enums.py +40 -0
  10. nexo/schemas/error/metadata.py +15 -0
  11. nexo/schemas/error/spec.py +312 -0
  12. nexo/schemas/exception/__init__.py +0 -0
  13. nexo/schemas/exception/exc.py +911 -0
  14. nexo/schemas/exception/factory.py +1928 -0
  15. nexo/schemas/exception/handlers.py +110 -0
  16. nexo/schemas/google.py +14 -0
  17. nexo/schemas/key/__init__.py +0 -0
  18. nexo/schemas/key/rsa.py +131 -0
  19. nexo/schemas/metadata.py +21 -0
  20. nexo/schemas/mixins/__init__.py +0 -0
  21. nexo/schemas/mixins/filter.py +140 -0
  22. nexo/schemas/mixins/general.py +65 -0
  23. nexo/schemas/mixins/hierarchy.py +19 -0
  24. nexo/schemas/mixins/identity.py +387 -0
  25. nexo/schemas/mixins/parameter.py +50 -0
  26. nexo/schemas/mixins/service.py +40 -0
  27. nexo/schemas/mixins/sort.py +111 -0
  28. nexo/schemas/mixins/timestamp.py +192 -0
  29. nexo/schemas/model.py +240 -0
  30. nexo/schemas/operation/__init__.py +0 -0
  31. nexo/schemas/operation/action/__init__.py +9 -0
  32. nexo/schemas/operation/action/base.py +14 -0
  33. nexo/schemas/operation/action/resource.py +371 -0
  34. nexo/schemas/operation/action/status.py +8 -0
  35. nexo/schemas/operation/action/system.py +6 -0
  36. nexo/schemas/operation/action/websocket.py +6 -0
  37. nexo/schemas/operation/base.py +289 -0
  38. nexo/schemas/operation/constants.py +18 -0
  39. nexo/schemas/operation/context.py +68 -0
  40. nexo/schemas/operation/dependency.py +26 -0
  41. nexo/schemas/operation/enums.py +168 -0
  42. nexo/schemas/operation/extractor.py +36 -0
  43. nexo/schemas/operation/mixins.py +53 -0
  44. nexo/schemas/operation/request.py +1066 -0
  45. nexo/schemas/operation/resource.py +839 -0
  46. nexo/schemas/operation/system.py +55 -0
  47. nexo/schemas/operation/websocket.py +55 -0
  48. nexo/schemas/pagination.py +67 -0
  49. nexo/schemas/parameter.py +60 -0
  50. nexo/schemas/payload.py +116 -0
  51. nexo/schemas/resource.py +64 -0
  52. nexo/schemas/response.py +1041 -0
  53. nexo/schemas/security/__init__.py +0 -0
  54. nexo/schemas/security/api_key.py +63 -0
  55. nexo/schemas/security/authentication.py +848 -0
  56. nexo/schemas/security/authorization.py +922 -0
  57. nexo/schemas/security/enums.py +32 -0
  58. nexo/schemas/security/impersonation.py +179 -0
  59. nexo/schemas/security/token.py +402 -0
  60. nexo/schemas/security/types.py +17 -0
  61. nexo/schemas/success/__init__.py +0 -0
  62. nexo/schemas/success/descriptor.py +100 -0
  63. nexo/schemas/success/enums.py +23 -0
  64. nexo/schemas/user_agent.py +46 -0
  65. nexo_schemas-0.0.16.dist-info/METADATA +87 -0
  66. nexo_schemas-0.0.16.dist-info/RECORD +69 -0
  67. nexo_schemas-0.0.16.dist-info/WHEEL +5 -0
  68. nexo_schemas-0.0.16.dist-info/licenses/LICENSE +21 -0
  69. nexo_schemas-0.0.16.dist-info/top_level.txt +1 -0
@@ -0,0 +1,476 @@
1
+ from pydantic import BaseModel, Field
2
+ from typing import Any, Generic, Literal, Type, TypeVar, overload
3
+ from typing_extensions import Annotated
4
+ from nexo.types.string import OptListOfStrs, OptStr
5
+ from .descriptor import (
6
+ ErrorDescriptorT,
7
+ ErrorDescriptorMixin,
8
+ BadRequestErrorDescriptor,
9
+ UnauthorizedErrorDescriptor,
10
+ ForbiddenErrorDescriptor,
11
+ NotFoundErrorDescriptor,
12
+ MethodNotAllowedErrorDescriptor,
13
+ ConflictErrorDescriptor,
14
+ UnprocessableEntityErrorDescriptor,
15
+ TooManyRequestsErrorDescriptor,
16
+ InternalServerErrorDescriptor,
17
+ NotImplementedErrorDescriptor,
18
+ BadGatewayErrorDescriptor,
19
+ ServiceUnavailableErrorDescriptor,
20
+ ErrorDescriptorFactory,
21
+ )
22
+ from .enums import ErrorCode
23
+ from .metadata import ErrorMetadata, ErrorMetadataMixin
24
+ from .spec import (
25
+ ErrorSpecT,
26
+ ErrorSpecMixin,
27
+ BadRequestErrorSpec,
28
+ UnauthorizedErrorSpec,
29
+ ForbiddenErrorSpec,
30
+ NotFoundErrorSpec,
31
+ MethodNotAllowedErrorSpec,
32
+ ConflictErrorSpec,
33
+ UnprocessableEntityErrorSpec,
34
+ TooManyRequestsErrorSpec,
35
+ InternalServerErrorSpec,
36
+ NotImplementedErrorSpec,
37
+ BadGatewayErrorSpec,
38
+ ServiceUnavailableErrorSpec,
39
+ ErrorSpecFactory,
40
+ )
41
+
42
+
43
+ class Error(
44
+ ErrorMetadataMixin,
45
+ ErrorDescriptorMixin[ErrorDescriptorT],
46
+ ErrorSpecMixin[ErrorSpecT],
47
+ Generic[ErrorSpecT, ErrorDescriptorT],
48
+ ):
49
+ pass
50
+
51
+
52
+ class BadRequestError(Error[BadRequestErrorSpec, BadRequestErrorDescriptor]):
53
+ spec: Annotated[
54
+ BadRequestErrorSpec, Field(..., description="Bad request error spec")
55
+ ] = BadRequestErrorSpec()
56
+ descriptor: Annotated[
57
+ BadRequestErrorDescriptor,
58
+ Field(..., description="Bad request error descriptor"),
59
+ ] = BadRequestErrorDescriptor()
60
+
61
+
62
+ class UnauthorizedError(Error[UnauthorizedErrorSpec, UnauthorizedErrorDescriptor]):
63
+ spec: Annotated[
64
+ UnauthorizedErrorSpec, Field(..., description="Unauthorized error spec")
65
+ ] = UnauthorizedErrorSpec()
66
+ descriptor: Annotated[
67
+ UnauthorizedErrorDescriptor,
68
+ Field(..., description="Unauthorized error descriptor"),
69
+ ] = UnauthorizedErrorDescriptor()
70
+
71
+
72
+ class ForbiddenError(Error[ForbiddenErrorSpec, ForbiddenErrorDescriptor]):
73
+ spec: Annotated[
74
+ ForbiddenErrorSpec, Field(..., description="Forbidden error spec")
75
+ ] = ForbiddenErrorSpec()
76
+ descriptor: Annotated[
77
+ ForbiddenErrorDescriptor, Field(..., description="Forbidden error descriptor")
78
+ ] = ForbiddenErrorDescriptor()
79
+
80
+
81
+ class NotFoundError(Error[NotFoundErrorSpec, NotFoundErrorDescriptor]):
82
+ spec: Annotated[
83
+ NotFoundErrorSpec, Field(..., description="Not found error spec")
84
+ ] = NotFoundErrorSpec()
85
+ descriptor: Annotated[
86
+ NotFoundErrorDescriptor, Field(..., description="Not found error descriptor")
87
+ ] = NotFoundErrorDescriptor()
88
+
89
+
90
+ class MethodNotAllowedError(
91
+ Error[MethodNotAllowedErrorSpec, MethodNotAllowedErrorDescriptor]
92
+ ):
93
+ spec: Annotated[
94
+ MethodNotAllowedErrorSpec,
95
+ Field(..., description="Method not allowed error spec"),
96
+ ] = MethodNotAllowedErrorSpec()
97
+ descriptor: Annotated[
98
+ MethodNotAllowedErrorDescriptor,
99
+ Field(..., description="Method not allowed error descriptor"),
100
+ ] = MethodNotAllowedErrorDescriptor()
101
+
102
+
103
+ class ConflictError(Error[ConflictErrorSpec, ConflictErrorDescriptor]):
104
+ spec: Annotated[
105
+ ConflictErrorSpec, Field(..., description="Conflict error spec")
106
+ ] = ConflictErrorSpec()
107
+ descriptor: Annotated[
108
+ ConflictErrorDescriptor, Field(..., description="Conflict error descriptor")
109
+ ] = ConflictErrorDescriptor()
110
+
111
+
112
+ class UnprocessableEntityError(
113
+ Error[UnprocessableEntityErrorSpec, UnprocessableEntityErrorDescriptor]
114
+ ):
115
+ spec: Annotated[
116
+ UnprocessableEntityErrorSpec,
117
+ Field(..., description="Unprocessable entity error spec"),
118
+ ] = UnprocessableEntityErrorSpec()
119
+ descriptor: Annotated[
120
+ UnprocessableEntityErrorDescriptor,
121
+ Field(..., description="Unprocessable entity error descriptor"),
122
+ ] = UnprocessableEntityErrorDescriptor()
123
+
124
+
125
+ class TooManyRequestsError(
126
+ Error[TooManyRequestsErrorSpec, TooManyRequestsErrorDescriptor]
127
+ ):
128
+ spec: Annotated[
129
+ TooManyRequestsErrorSpec, Field(..., description="Too many requests error spec")
130
+ ] = TooManyRequestsErrorSpec()
131
+ descriptor: Annotated[
132
+ TooManyRequestsErrorDescriptor,
133
+ Field(..., description="Too many requests error descriptor"),
134
+ ] = TooManyRequestsErrorDescriptor()
135
+
136
+
137
+ class InternalServerError(
138
+ Error[InternalServerErrorSpec, InternalServerErrorDescriptor]
139
+ ):
140
+ spec: Annotated[
141
+ InternalServerErrorSpec, Field(..., description="Internal server error spec")
142
+ ] = InternalServerErrorSpec()
143
+ descriptor: Annotated[
144
+ InternalServerErrorDescriptor,
145
+ Field(..., description="Internal server error descriptor"),
146
+ ] = InternalServerErrorDescriptor()
147
+
148
+
149
+ class NotImplementedError(
150
+ Error[NotImplementedErrorSpec, NotImplementedErrorDescriptor]
151
+ ):
152
+ spec: Annotated[
153
+ NotImplementedErrorSpec, Field(..., description="Not implemented error spec")
154
+ ] = NotImplementedErrorSpec()
155
+ descriptor: Annotated[
156
+ NotImplementedErrorDescriptor,
157
+ Field(..., description="Not implemented error descriptor"),
158
+ ] = NotImplementedErrorDescriptor()
159
+
160
+
161
+ class BadGatewayError(Error[BadGatewayErrorSpec, BadGatewayErrorDescriptor]):
162
+ spec: Annotated[
163
+ BadGatewayErrorSpec, Field(..., description="Bad gateway error spec")
164
+ ] = BadGatewayErrorSpec()
165
+ descriptor: Annotated[
166
+ BadGatewayErrorDescriptor,
167
+ Field(..., description="Bad gateway error descriptor"),
168
+ ] = BadGatewayErrorDescriptor()
169
+
170
+
171
+ class ServiceUnavailableError(
172
+ Error[ServiceUnavailableErrorSpec, ServiceUnavailableErrorDescriptor]
173
+ ):
174
+ spec: Annotated[
175
+ ServiceUnavailableErrorSpec,
176
+ Field(..., description="Service unavailable error spec"),
177
+ ] = ServiceUnavailableErrorSpec()
178
+ descriptor: Annotated[
179
+ ServiceUnavailableErrorDescriptor,
180
+ Field(..., description="Service unavailable error descriptor"),
181
+ ] = ServiceUnavailableErrorDescriptor()
182
+
183
+
184
+ AnyErrorType = (
185
+ Type[BadRequestError]
186
+ | Type[UnauthorizedError]
187
+ | Type[ForbiddenError]
188
+ | Type[NotFoundError]
189
+ | Type[MethodNotAllowedError]
190
+ | Type[ConflictError]
191
+ | Type[UnprocessableEntityError]
192
+ | Type[TooManyRequestsError]
193
+ | Type[InternalServerError]
194
+ | Type[NotImplementedError]
195
+ | Type[BadGatewayError]
196
+ | Type[ServiceUnavailableError]
197
+ )
198
+ AnyError = (
199
+ BadRequestError
200
+ | UnauthorizedError
201
+ | ForbiddenError
202
+ | NotFoundError
203
+ | MethodNotAllowedError
204
+ | ConflictError
205
+ | UnprocessableEntityError
206
+ | TooManyRequestsError
207
+ | InternalServerError
208
+ | NotImplementedError
209
+ | BadGatewayError
210
+ | ServiceUnavailableError
211
+ )
212
+ AnyErrorT = TypeVar("AnyErrorT", bound=AnyError)
213
+ OptAnyError = AnyError | None
214
+ OptAnyErrorT = TypeVar("OptAnyErrorT", bound=OptAnyError)
215
+
216
+
217
+ class ErrorFactory:
218
+ @overload
219
+ @staticmethod
220
+ def cls_from_code(
221
+ code: Literal[ErrorCode.BAD_REQUEST, 400],
222
+ /,
223
+ ) -> Type[BadRequestError]: ...
224
+ @overload
225
+ @staticmethod
226
+ def cls_from_code(
227
+ code: Literal[ErrorCode.UNAUTHORIZED, 401],
228
+ /,
229
+ ) -> Type[UnauthorizedError]: ...
230
+ @overload
231
+ @staticmethod
232
+ def cls_from_code(
233
+ code: Literal[ErrorCode.FORBIDDEN, 403],
234
+ /,
235
+ ) -> Type[ForbiddenError]: ...
236
+ @overload
237
+ @staticmethod
238
+ def cls_from_code(
239
+ code: Literal[ErrorCode.NOT_FOUND, 404],
240
+ /,
241
+ ) -> Type[NotFoundError]: ...
242
+ @overload
243
+ @staticmethod
244
+ def cls_from_code(
245
+ code: Literal[ErrorCode.METHOD_NOT_ALLOWED, 405],
246
+ /,
247
+ ) -> Type[MethodNotAllowedError]: ...
248
+ @overload
249
+ @staticmethod
250
+ def cls_from_code(
251
+ code: Literal[ErrorCode.CONFLICT, 409],
252
+ /,
253
+ ) -> Type[ConflictError]: ...
254
+ @overload
255
+ @staticmethod
256
+ def cls_from_code(
257
+ code: Literal[ErrorCode.UNPROCESSABLE_ENTITY, 422],
258
+ /,
259
+ ) -> Type[UnprocessableEntityError]: ...
260
+ @overload
261
+ @staticmethod
262
+ def cls_from_code(
263
+ code: Literal[ErrorCode.TOO_MANY_REQUESTS, 429],
264
+ /,
265
+ ) -> Type[TooManyRequestsError]: ...
266
+ @overload
267
+ @staticmethod
268
+ def cls_from_code(
269
+ code: Literal[ErrorCode.INTERNAL_SERVER_ERROR, 500],
270
+ /,
271
+ ) -> Type[InternalServerError]: ...
272
+ @overload
273
+ @staticmethod
274
+ def cls_from_code(
275
+ code: Literal[ErrorCode.NOT_IMPLEMENTED, 501],
276
+ /,
277
+ ) -> Type[NotImplementedError]: ...
278
+ @overload
279
+ @staticmethod
280
+ def cls_from_code(
281
+ code: Literal[ErrorCode.BAD_GATEWAY, 502],
282
+ /,
283
+ ) -> Type[BadGatewayError]: ...
284
+ @overload
285
+ @staticmethod
286
+ def cls_from_code(
287
+ code: Literal[ErrorCode.SERVICE_UNAVAILABLE, 503],
288
+ /,
289
+ ) -> Type[ServiceUnavailableError]: ...
290
+ @overload
291
+ @staticmethod
292
+ def cls_from_code(
293
+ code: ErrorCode | int,
294
+ /,
295
+ ) -> AnyErrorType: ...
296
+ @staticmethod
297
+ def cls_from_code(
298
+ code: ErrorCode | int,
299
+ /,
300
+ ) -> AnyErrorType:
301
+ if code is ErrorCode.BAD_REQUEST or code == 400:
302
+ return BadRequestError
303
+ elif code is ErrorCode.UNAUTHORIZED or code == 401:
304
+ return UnauthorizedError
305
+ elif code is ErrorCode.FORBIDDEN or code == 403:
306
+ return ForbiddenError
307
+ elif code is ErrorCode.NOT_FOUND or code == 404:
308
+ return NotFoundError
309
+ elif code is ErrorCode.METHOD_NOT_ALLOWED or code == 405:
310
+ return MethodNotAllowedError
311
+ elif code is ErrorCode.CONFLICT or code == 409:
312
+ return ConflictError
313
+ elif code is ErrorCode.UNPROCESSABLE_ENTITY or code == 422:
314
+ return UnprocessableEntityError
315
+ elif code is ErrorCode.TOO_MANY_REQUESTS or code == 429:
316
+ return TooManyRequestsError
317
+ elif code is ErrorCode.INTERNAL_SERVER_ERROR or code == 500:
318
+ return InternalServerError
319
+ elif code is ErrorCode.NOT_IMPLEMENTED or code == 501:
320
+ return NotImplementedError
321
+ elif code is ErrorCode.BAD_GATEWAY or code == 502:
322
+ return BadGatewayError
323
+ elif code is ErrorCode.SERVICE_UNAVAILABLE or code == 503:
324
+ return ServiceUnavailableError
325
+ raise ValueError(f"Unable to determine error class for code: {code}")
326
+
327
+ @overload
328
+ @staticmethod
329
+ def from_code(
330
+ code: Literal[ErrorCode.BAD_REQUEST, 400],
331
+ *,
332
+ message: OptStr = None,
333
+ description: OptStr = None,
334
+ details: Any = None,
335
+ traceback: OptListOfStrs = None,
336
+ ) -> BadRequestError: ...
337
+ @overload
338
+ @staticmethod
339
+ def from_code(
340
+ code: Literal[ErrorCode.UNAUTHORIZED, 401],
341
+ *,
342
+ message: OptStr = None,
343
+ description: OptStr = None,
344
+ details: Any = None,
345
+ traceback: OptListOfStrs = None,
346
+ ) -> UnauthorizedError: ...
347
+ @overload
348
+ @staticmethod
349
+ def from_code(
350
+ code: Literal[ErrorCode.FORBIDDEN, 403],
351
+ *,
352
+ message: OptStr = None,
353
+ description: OptStr = None,
354
+ details: Any = None,
355
+ traceback: OptListOfStrs = None,
356
+ ) -> ForbiddenError: ...
357
+ @overload
358
+ @staticmethod
359
+ def from_code(
360
+ code: Literal[ErrorCode.NOT_FOUND, 404],
361
+ *,
362
+ message: OptStr = None,
363
+ description: OptStr = None,
364
+ details: Any = None,
365
+ traceback: OptListOfStrs = None,
366
+ ) -> NotFoundError: ...
367
+ @overload
368
+ @staticmethod
369
+ def from_code(
370
+ code: Literal[ErrorCode.METHOD_NOT_ALLOWED, 405],
371
+ *,
372
+ message: OptStr = None,
373
+ description: OptStr = None,
374
+ details: Any = None,
375
+ traceback: OptListOfStrs = None,
376
+ ) -> MethodNotAllowedError: ...
377
+ @overload
378
+ @staticmethod
379
+ def from_code(
380
+ code: Literal[ErrorCode.CONFLICT, 409],
381
+ *,
382
+ message: OptStr = None,
383
+ description: OptStr = None,
384
+ details: Any = None,
385
+ traceback: OptListOfStrs = None,
386
+ ) -> ConflictError: ...
387
+ @overload
388
+ @staticmethod
389
+ def from_code(
390
+ code: Literal[ErrorCode.UNPROCESSABLE_ENTITY, 422],
391
+ *,
392
+ message: OptStr = None,
393
+ description: OptStr = None,
394
+ details: Any = None,
395
+ traceback: OptListOfStrs = None,
396
+ ) -> UnprocessableEntityError: ...
397
+ @overload
398
+ @staticmethod
399
+ def from_code(
400
+ code: Literal[ErrorCode.TOO_MANY_REQUESTS, 429],
401
+ *,
402
+ message: OptStr = None,
403
+ description: OptStr = None,
404
+ details: Any = None,
405
+ traceback: OptListOfStrs = None,
406
+ ) -> TooManyRequestsError: ...
407
+ @overload
408
+ @staticmethod
409
+ def from_code(
410
+ code: Literal[ErrorCode.INTERNAL_SERVER_ERROR, 500],
411
+ *,
412
+ message: OptStr = None,
413
+ description: OptStr = None,
414
+ details: Any = None,
415
+ traceback: OptListOfStrs = None,
416
+ ) -> InternalServerError: ...
417
+ @overload
418
+ @staticmethod
419
+ def from_code(
420
+ code: Literal[ErrorCode.NOT_IMPLEMENTED, 501],
421
+ *,
422
+ message: OptStr = None,
423
+ description: OptStr = None,
424
+ details: Any = None,
425
+ traceback: OptListOfStrs = None,
426
+ ) -> NotImplementedError: ...
427
+ @overload
428
+ @staticmethod
429
+ def from_code(
430
+ code: Literal[ErrorCode.BAD_GATEWAY, 502],
431
+ *,
432
+ message: OptStr = None,
433
+ description: OptStr = None,
434
+ details: Any = None,
435
+ traceback: OptListOfStrs = None,
436
+ ) -> BadGatewayError: ...
437
+ @overload
438
+ @staticmethod
439
+ def from_code(
440
+ code: Literal[ErrorCode.SERVICE_UNAVAILABLE, 503],
441
+ *,
442
+ message: OptStr = None,
443
+ description: OptStr = None,
444
+ details: Any = None,
445
+ traceback: OptListOfStrs = None,
446
+ ) -> ServiceUnavailableError: ...
447
+ @overload
448
+ @staticmethod
449
+ def from_code(
450
+ code: ErrorCode | int,
451
+ *,
452
+ message: OptStr = None,
453
+ description: OptStr = None,
454
+ details: Any = None,
455
+ traceback: OptListOfStrs = None,
456
+ ) -> AnyError: ...
457
+ @staticmethod
458
+ def from_code(
459
+ code: ErrorCode | int,
460
+ *,
461
+ message: OptStr = None,
462
+ description: OptStr = None,
463
+ details: Any = None,
464
+ traceback: OptListOfStrs = None,
465
+ ) -> AnyError:
466
+ return ErrorFactory.cls_from_code(code)(
467
+ spec=ErrorSpecFactory.from_code(code), # type: ignore
468
+ descriptor=ErrorDescriptorFactory.from_code(
469
+ code, message=message, description=description
470
+ ), # type: ignore
471
+ metadata=ErrorMetadata(details=details, traceback=traceback),
472
+ )
473
+
474
+
475
+ class ErrorMixin(BaseModel, Generic[OptAnyErrorT]):
476
+ error: OptAnyErrorT = Field(..., description="Error")
@@ -0,0 +1,50 @@
1
+ from typing import Dict
2
+ from .enums import ErrorCode, ErrorType
3
+
4
+
5
+ ERROR_CODE_STATUS_CODE_MAP: Dict[ErrorCode, int] = {
6
+ ErrorCode.BAD_REQUEST: 400,
7
+ ErrorCode.UNAUTHORIZED: 401,
8
+ ErrorCode.FORBIDDEN: 403,
9
+ ErrorCode.NOT_FOUND: 404,
10
+ ErrorCode.METHOD_NOT_ALLOWED: 405,
11
+ ErrorCode.CONFLICT: 409,
12
+ ErrorCode.UNPROCESSABLE_ENTITY: 422,
13
+ ErrorCode.TOO_MANY_REQUESTS: 429,
14
+ ErrorCode.INTERNAL_SERVER_ERROR: 500,
15
+ ErrorCode.NOT_IMPLEMENTED: 501,
16
+ ErrorCode.BAD_GATEWAY: 502,
17
+ ErrorCode.SERVICE_UNAVAILABLE: 503,
18
+ }
19
+
20
+
21
+ ERROR_TYPE_STATUS_CODE_MAP: Dict[ErrorType, int] = {
22
+ ErrorType.BAD_REQUEST: 400,
23
+ ErrorType.UNAUTHORIZED: 401,
24
+ ErrorType.FORBIDDEN: 403,
25
+ ErrorType.NOT_FOUND: 404,
26
+ ErrorType.METHOD_NOT_ALLOWED: 405,
27
+ ErrorType.CONFLICT: 409,
28
+ ErrorType.UNPROCESSABLE_ENTITY: 422,
29
+ ErrorType.TOO_MANY_REQUESTS: 429,
30
+ ErrorType.INTERNAL_SERVER_ERROR: 500,
31
+ ErrorType.NOT_IMPLEMENTED: 501,
32
+ ErrorType.BAD_GATEWAY: 502,
33
+ ErrorType.SERVICE_UNAVAILABLE: 503,
34
+ }
35
+
36
+
37
+ STATUS_CODE_ERROR_TYPE_MAP: Dict[int, ErrorType] = {
38
+ 400: ErrorType.BAD_REQUEST,
39
+ 401: ErrorType.UNAUTHORIZED,
40
+ 403: ErrorType.FORBIDDEN,
41
+ 404: ErrorType.NOT_FOUND,
42
+ 405: ErrorType.METHOD_NOT_ALLOWED,
43
+ 409: ErrorType.CONFLICT,
44
+ 422: ErrorType.UNPROCESSABLE_ENTITY,
45
+ 429: ErrorType.TOO_MANY_REQUESTS,
46
+ 500: ErrorType.INTERNAL_SERVER_ERROR,
47
+ 501: ErrorType.NOT_IMPLEMENTED,
48
+ 502: ErrorType.BAD_GATEWAY,
49
+ 503: ErrorType.SERVICE_UNAVAILABLE,
50
+ }