diff --git a/diracx-routers/src/diracx/routers/__init__.py b/diracx-routers/src/diracx/routers/__init__.py index baa99784..ef464d24 100644 --- a/diracx-routers/src/diracx/routers/__init__.py +++ b/diracx-routers/src/diracx/routers/__init__.py @@ -54,7 +54,7 @@ logger = logging.getLogger(__name__) -DIRACX_MIN_CLIENT_VERSION = "0.0.1" +DIRACX_MIN_CLIENT_VERSION = "0.0.1a1" ###########################################3 @@ -464,12 +464,15 @@ def __init__(self, app: FastAPI): async def dispatch(self, request: Request, call_next) -> Response: client_version = request.headers.get("DiracX-Client-Version") + if client_version and self.is_version_too_old(client_version): # When comes from Swagger or Web, there is no client version header. # This is not managed here. - raise HTTPException( + # Return a JSONResponse because the HTTPException + # is not handled nicely in the middleware + return JSONResponse( status_code=HTTPStatus.UPGRADE_REQUIRED, - detail=f"Client version ({client_version}) not recent enough (>= {self.min_client_version}). Upgrade.", + content=f"Client version ({client_version}) not recent enough (>= {self.min_client_version}). Upgrade.", ) response = await call_next(request)