1
1
import orjson
2
2
from fastapi import FastAPI , Request
3
+ from fastapi .exceptions import ResponseValidationError
3
4
from fastapi .responses import JSONResponse
4
5
from rotoger import AppStructLogger
5
6
from sqlalchemy .exc import SQLAlchemyError
6
- from fastapi .exceptions import ResponseValidationError
7
7
8
8
logger = AppStructLogger ().get_logger ()
9
9
10
- #TODO: add reasoning for this in readme plus higligh using re-raise in db session
10
+
11
+ # TODO: add reasoning for this in readme plus higligh using re-raise in db session
11
12
async def sqlalchemy_exception_handler (
12
13
request : Request , exc : SQLAlchemyError
13
14
) -> JSONResponse :
@@ -32,7 +33,7 @@ async def sqlalchemy_exception_handler(
32
33
33
34
34
35
async def response_validation_exception_handler (
35
- request : Request , exc : ResponseValidationError
36
+ request : Request , exc : ResponseValidationError
36
37
) -> JSONResponse :
37
38
request_path = request .url .path
38
39
try :
@@ -76,4 +77,6 @@ async def response_validation_exception_handler(
76
77
def register_exception_handlers (app : FastAPI ) -> None :
77
78
"""Register all exception handlers with the FastAPI app."""
78
79
app .add_exception_handler (SQLAlchemyError , sqlalchemy_exception_handler )
79
- app .add_exception_handler (ResponseValidationError , response_validation_exception_handler )
80
+ app .add_exception_handler (
81
+ ResponseValidationError , response_validation_exception_handler
82
+ )
0 commit comments