af-fastapi-exceptions 0.0.3__tar.gz → 0.0.5__tar.gz
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.
- {af_fastapi_exceptions-0.0.3 → af_fastapi_exceptions-0.0.5}/PKG-INFO +1 -1
- {af_fastapi_exceptions-0.0.3 → af_fastapi_exceptions-0.0.5}/pyproject.toml +1 -1
- {af_fastapi_exceptions-0.0.3 → af_fastapi_exceptions-0.0.5}/src/allfly/fastapi/exceptions/exceptions.py +9 -0
- {af_fastapi_exceptions-0.0.3 → af_fastapi_exceptions-0.0.5}/src/allfly/fastapi/exceptions/middleware.py +8 -9
- {af_fastapi_exceptions-0.0.3 → af_fastapi_exceptions-0.0.5}/README.md +0 -0
- {af_fastapi_exceptions-0.0.3 → af_fastapi_exceptions-0.0.5}/src/allfly/fastapi/exceptions/__init__.py +0 -0
- {af_fastapi_exceptions-0.0.3 → af_fastapi_exceptions-0.0.5}/src/allfly/fastapi/exceptions/py.typed +0 -0
|
@@ -54,12 +54,21 @@ class ResourceConflictError(ServiceError):
|
|
|
54
54
|
status_code = status.HTTP_409_CONFLICT
|
|
55
55
|
super().__init__(message, status_code)
|
|
56
56
|
|
|
57
|
+
class ResourceConflictWarning(ServiceWarning):
|
|
58
|
+
def __init__(self, message="Request creates a conflict"):
|
|
59
|
+
status_code = status.HTTP_409_CONFLICT
|
|
60
|
+
super().__init__(message, status_code)
|
|
57
61
|
|
|
58
62
|
class UnprocessableRequestError(ServiceError):
|
|
59
63
|
def __init__(self, message="Unprocessable Request"):
|
|
60
64
|
status_code = status.HTTP_422_UNPROCESSABLE_ENTITY
|
|
61
65
|
super().__init__(message, status_code)
|
|
62
66
|
|
|
67
|
+
class UnprocessableRequestWarning(ServiceWarning):
|
|
68
|
+
def __init__(self, message="Unprocessable Request"):
|
|
69
|
+
status_code = status.HTTP_422_UNPROCESSABLE_ENTITY
|
|
70
|
+
super().__init__(message, status_code)
|
|
71
|
+
|
|
63
72
|
|
|
64
73
|
class UnsupportedFeatureError(ServiceWarning):
|
|
65
74
|
def __init__(self, message="Not implemented"):
|
|
@@ -3,7 +3,6 @@ from typing import Any, Protocol
|
|
|
3
3
|
|
|
4
4
|
from fastapi.exceptions import RequestValidationError
|
|
5
5
|
from loguru import logger
|
|
6
|
-
from starlette import status
|
|
7
6
|
from starlette.middleware.base import BaseHTTPMiddleware
|
|
8
7
|
from starlette.requests import Request
|
|
9
8
|
from starlette.responses import JSONResponse
|
|
@@ -35,7 +34,7 @@ def _handle_unexpected_error(
|
|
|
35
34
|
return JSONResponse(
|
|
36
35
|
content=body.model_dump(mode="json", exclude_none=True),
|
|
37
36
|
media_type="application/json",
|
|
38
|
-
status_code=
|
|
37
|
+
status_code=500,
|
|
39
38
|
)
|
|
40
39
|
|
|
41
40
|
|
|
@@ -77,7 +76,7 @@ def build_validation_handler(error_model: type[ApiErrorBody]):
|
|
|
77
76
|
logger.warning(detailed_error)
|
|
78
77
|
body = error_model(message="Request Validation Error", errors=errors)
|
|
79
78
|
return JSONResponse(
|
|
80
|
-
status_code=
|
|
79
|
+
status_code=422,
|
|
81
80
|
content=body.model_dump(mode="json", exclude_none=True),
|
|
82
81
|
)
|
|
83
82
|
|
|
@@ -86,18 +85,18 @@ def build_validation_handler(error_model: type[ApiErrorBody]):
|
|
|
86
85
|
|
|
87
86
|
def build_error_responses(error_model: type[ApiErrorBody]) -> dict:
|
|
88
87
|
return {
|
|
89
|
-
|
|
88
|
+
401: {
|
|
90
89
|
"model": error_model,
|
|
91
90
|
"description": "Authentication data in the request is invalid",
|
|
92
91
|
},
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
92
|
+
403: {"model": error_model, "description": "Not authorized"},
|
|
93
|
+
404: {"model": error_model, "description": "Not found"},
|
|
94
|
+
409: {"model": error_model, "description": "Resource conflict detected"},
|
|
95
|
+
422: {
|
|
97
96
|
"model": error_model,
|
|
98
97
|
"description": "Understood the request, but can't and won't process it",
|
|
99
98
|
},
|
|
100
|
-
|
|
99
|
+
400: {"model": error_model, "description": "Bad request"},
|
|
101
100
|
}
|
|
102
101
|
|
|
103
102
|
|
|
File without changes
|
|
File without changes
|
{af_fastapi_exceptions-0.0.3 → af_fastapi_exceptions-0.0.5}/src/allfly/fastapi/exceptions/py.typed
RENAMED
|
File without changes
|