11# SPDX-FileCopyrightText: 2023-2024 MTS PJSC
22# SPDX-License-Identifier: Apache-2.0
33from fastapi import FastAPI , HTTPException
4+ from fastapi .exceptions import RequestValidationError
5+ from pydantic import ValidationError
46from starlette .middleware .cors import CORSMiddleware
57
68from syncmaster .backend .api .deps import (
1315from syncmaster .backend .handler import (
1416 http_exception_handler ,
1517 syncmsater_exception_handler ,
18+ unknown_exception_handler ,
19+ validation_exception_handler ,
1620)
1721from syncmaster .config import Settings
1822from syncmaster .db .factory import create_engine , create_session_factory , get_uow
@@ -33,8 +37,11 @@ def application_factory(settings: Settings) -> FastAPI:
3337 )
3438
3539 application .include_router (api_router )
36- application .exception_handler (HTTPException )(http_exception_handler )
40+ application .exception_handler (RequestValidationError )(validation_exception_handler )
41+ application .exception_handler (ValidationError )(validation_exception_handler )
3742 application .exception_handler (SyncmasterError )(syncmsater_exception_handler )
43+ application .exception_handler (HTTPException )(http_exception_handler )
44+ application .exception_handler (Exception )(unknown_exception_handler )
3845
3946 engine = create_engine (connection_uri = settings .build_db_connection_uri ())
4047 session_factory = create_session_factory (engine = engine )
0 commit comments