File tree Expand file tree Collapse file tree 3 files changed +10
-7
lines changed
services/datcore-adapter/src/simcore_service_datcore_adapter/api/errors Expand file tree Collapse file tree 3 files changed +10
-7
lines changed Original file line number Diff line number Diff line change 1- from typing import Callable , Optional
1+ from typing import Callable
22
33from fastapi import HTTPException
44from fastapi .encoders import jsonable_encoder
55from starlette .requests import Request
66from starlette .responses import JSONResponse
77
88
9- async def http_error_handler (_ : Request , exc : HTTPException ) -> JSONResponse :
9+ async def http_error_handler (_ : Request , exc : Exception ) -> JSONResponse :
10+ assert isinstance (exc , HTTPException ) # nosec
1011 return JSONResponse (
1112 content = jsonable_encoder ({"errors" : [exc .detail ]}), status_code = exc .status_code
1213 )
@@ -16,7 +17,7 @@ def make_http_error_handler_for_exception(
1617 status_code : int ,
1718 exception_cls : type [BaseException ],
1819 * ,
19- override_detail_message : Optional [ str ] = None ,
20+ override_detail_message : str | None = None ,
2021) -> Callable :
2122 """
2223 Produces a handler for BaseException-type exceptions which converts them
Original file line number Diff line number Diff line change 77
88async def botocore_exceptions_handler (
99 _ : Request ,
10- exc : ClientError ,
10+ exc : Exception ,
1111) -> JSONResponse :
12+ assert isinstance (exc , ClientError ) # nosec
13+ assert "Error" in exc .response # nosec
14+ assert "Code" in exc .response ["Error" ] # nosec
1215 if exc .response ["Error" ]["Code" ] == "NotAuthorizedException" :
1316 return JSONResponse (
1417 content = jsonable_encoder ({"errors" : exc .response ["Error" ]}),
Original file line number Diff line number Diff line change 1- from typing import Union
2-
31from fastapi .encoders import jsonable_encoder
42from fastapi .exceptions import RequestValidationError
53from fastapi .openapi .constants import REF_PREFIX
1210
1311async def http422_error_handler (
1412 _ : Request ,
15- exc : Union [ RequestValidationError , ValidationError ] ,
13+ exc : Exception ,
1614) -> JSONResponse :
15+ assert isinstance (exc , RequestValidationError | ValidationError ) # nosec
1716 return JSONResponse (
1817 content = jsonable_encoder ({"errors" : exc .errors ()}),
1918 status_code = HTTP_422_UNPROCESSABLE_ENTITY ,
You can’t perform that action at this time.
0 commit comments