|
1 | 1 | import logging
|
2 | 2 |
|
3 | 3 | from fastapi import FastAPI
|
4 |
| -from fastapi.exceptions import RequestValidationError |
5 | 4 | from fastapi_pagination import add_pagination
|
6 |
| -from httpx import HTTPError as HttpxException |
7 |
| -from models_library.basic_types import BootModeEnum |
8 | 5 | from servicelib.fastapi.profiler_middleware import ProfilerMiddleware
|
9 | 6 | from servicelib.logging_utils import config_all_loggers
|
10 |
| -from starlette import status |
11 |
| -from starlette.exceptions import HTTPException |
12 | 7 |
|
13 | 8 | from .._meta import API_VERSION, API_VTAG
|
14 |
| -from ..api.errors.custom_errors import custom_error_handler |
15 |
| -from ..api.errors.http_error import ( |
16 |
| - http_error_handler, |
17 |
| - make_http_error_handler_for_exception, |
18 |
| -) |
19 |
| -from ..api.errors.httpx_client_error import handle_httpx_client_exceptions |
20 |
| -from ..api.errors.log_handling_error import log_handling_error_handler |
21 |
| -from ..api.errors.validation_error import http422_error_handler |
22 | 9 | from ..api.root import create_router
|
23 | 10 | from ..api.routes.health import router as health_router
|
24 |
| -from ..models.custom_errors import CustomBaseError |
| 11 | +from ..errors import exception_handlers |
25 | 12 | from ..services import catalog, director_v2, storage, webserver
|
26 |
| -from ..services.log_streaming import LogDistributionBaseException |
27 | 13 | from ..services.rabbitmq import setup_rabbitmq
|
28 | 14 | from ._prometheus_instrumentation import setup_prometheus_instrumentation
|
29 | 15 | from .events import create_start_app_handler, create_stop_app_handler
|
@@ -97,31 +83,8 @@ def init_app(settings: ApplicationSettings | None = None) -> FastAPI:
|
97 | 83 | app.add_event_handler("startup", create_start_app_handler(app))
|
98 | 84 | app.add_event_handler("shutdown", create_stop_app_handler(app))
|
99 | 85 |
|
100 |
| - app.add_exception_handler(HTTPException, http_error_handler) |
101 |
| - app.add_exception_handler(HttpxException, handle_httpx_client_exceptions) |
102 |
| - app.add_exception_handler(RequestValidationError, http422_error_handler) |
103 |
| - app.add_exception_handler(LogDistributionBaseException, log_handling_error_handler) |
104 |
| - app.add_exception_handler(CustomBaseError, custom_error_handler) |
105 |
| - |
106 |
| - # SEE https://docs.python.org/3/library/exceptions.html#exception-hierarchy |
107 |
| - app.add_exception_handler( |
108 |
| - NotImplementedError, |
109 |
| - make_http_error_handler_for_exception( |
110 |
| - NotImplementedError, |
111 |
| - status.HTTP_501_NOT_IMPLEMENTED, |
112 |
| - detail_message="Endpoint not implemented", |
113 |
| - ), |
114 |
| - ) |
115 |
| - app.add_exception_handler( |
116 |
| - Exception, |
117 |
| - make_http_error_handler_for_exception( |
118 |
| - Exception, |
119 |
| - status.HTTP_500_INTERNAL_SERVER_ERROR, |
120 |
| - detail_message="Unexpected error", |
121 |
| - add_exception_to_message=(settings.SC_BOOT_MODE == BootModeEnum.DEBUG), |
122 |
| - add_oec_to_message=True, |
123 |
| - ), |
124 |
| - ) |
| 86 | + exception_handlers.setup(app) |
| 87 | + |
125 | 88 | if settings.API_SERVER_PROFILING:
|
126 | 89 | app.add_middleware(ProfilerMiddleware)
|
127 | 90 |
|
|
0 commit comments