|
26 | 26 | from uvicorn.logging import AccessFormatter, DefaultFormatter |
27 | 27 |
|
28 | 28 | from diracx.core.config import ConfigSource |
29 | | -from diracx.core.exceptions import DiracError, DiracHttpResponseError, NotReadyError |
| 29 | +from diracx.core.exceptions import DiracError, NotReadyError |
30 | 30 | from diracx.core.extensions import DiracEntryPoint, select_from_extension |
31 | 31 | from diracx.core.settings import FactorySettings, ServiceSettingsBase |
32 | 32 | from diracx.core.sources import AsyncCacheableSource |
@@ -327,9 +327,6 @@ def create_app_inner( |
327 | 327 | # with a subclass of Exception (https://mypy.readthedocs.io/en/latest/generics.html#variance-of-generic-types) |
328 | 328 | handler_signature = Callable[[Request, Exception], Response | Awaitable[Response]] |
329 | 329 | app.add_exception_handler(DiracError, cast(handler_signature, dirac_error_handler)) |
330 | | - app.add_exception_handler( |
331 | | - DiracHttpResponseError, cast(handler_signature, http_response_handler) |
332 | | - ) |
333 | 330 | app.add_exception_handler( |
334 | 331 | DBUnavailableError, cast(handler_signature, route_unavailable_error_hander) |
335 | 332 | ) |
@@ -427,17 +424,15 @@ def create_app() -> DiracFastAPI: |
427 | 424 |
|
428 | 425 |
|
429 | 426 | def dirac_error_handler(request: Request, exc: DiracError) -> Response: |
| 427 | + status_code = getattr(exc, "http_status_code", HTTPStatus.BAD_REQUEST) |
| 428 | + headers = getattr(exc, "http_headers", None) |
430 | 429 | return JSONResponse( |
431 | | - status_code=exc.http_status_code, |
| 430 | + status_code=status_code, |
432 | 431 | content={"detail": exc.detail}, |
433 | | - headers=exc.http_headers, |
| 432 | + headers=headers, |
434 | 433 | ) |
435 | 434 |
|
436 | 435 |
|
437 | | -def http_response_handler(request: Request, exc: DiracHttpResponseError) -> Response: |
438 | | - return JSONResponse(status_code=exc.status_code, content=exc.data) |
439 | | - |
440 | | - |
441 | 436 | def route_unavailable_error_hander(request: Request, exc: DBUnavailableError): |
442 | 437 | logger.warning( |
443 | 438 | "503 Service Unavailable: %s (path=%s)", |
@@ -505,7 +500,7 @@ async def is_db_unavailable(db: BaseSQLDB | BaseOSDB) -> str: |
505 | 500 | _db_alive_cache[db] = "" |
506 | 501 |
|
507 | 502 | except DBUnavailableError as e: |
508 | | - _db_alive_cache[db] = e.args[0] |
| 503 | + _db_alive_cache[db] = str(e) |
509 | 504 |
|
510 | 505 | return _db_alive_cache[db] |
511 | 506 |
|
|
0 commit comments