From f911eb18d24935001e71631db8f6a0b11cf5c021 Mon Sep 17 00:00:00 2001 From: Jacob Williamson Date: Thu, 7 May 2026 11:24:01 +0100 Subject: [PATCH] Handle blueapi connection error --- src/daq_queuing_service/api/errors.py | 15 ++++++++++++++- src/daq_queuing_service/app/app.py | 5 ----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/daq_queuing_service/api/errors.py b/src/daq_queuing_service/api/errors.py index e33b5e9..40a107f 100644 --- a/src/daq_queuing_service/api/errors.py +++ b/src/daq_queuing_service/api/errors.py @@ -1,4 +1,8 @@ -from blueapi.client.rest import InvalidParametersError, UnknownPlanError +from blueapi.client.rest import ( + InvalidParametersError, + ServiceUnavailableError, + UnknownPlanError, +) from fastapi import FastAPI, Request from fastapi.responses import JSONResponse @@ -15,6 +19,15 @@ def register_exception_handlers(app: FastAPI): + @app.exception_handler(ServiceUnavailableError) + async def service_unavailable_error( + request: Request, exception: ServiceUnavailableError + ): + return JSONResponse( + status_code=409, + content={"error": "blueapi_unavailable", "message": str(exception)}, + ) + @app.exception_handler(TaskInProgressError) async def task_in_progress_handler( request: Request, exception: TaskInProgressError diff --git a/src/daq_queuing_service/app/app.py b/src/daq_queuing_service/app/app.py index 295fb15..49df90a 100644 --- a/src/daq_queuing_service/app/app.py +++ b/src/daq_queuing_service/app/app.py @@ -18,11 +18,6 @@ from ._config import load_config -LOCAL_BLUEAPI_URL = "http://localhost:8000/" -I15_1_BLUEAPI_URL = "https://i15-1-blueapi.diamond.ac.uk/" -STOMP_URL = "tcp://localhost:61613" - - logging.basicConfig( level=logging.INFO, format="%(asctime)s [%(name)s] %(levelname)s: %(message)s" )