Skip to content

Commit

Permalink
MinVersion: lower it, and better error return
Browse files Browse the repository at this point in the history
  • Loading branch information
chaen committed Nov 21, 2024
1 parent e514bb8 commit 2e3e230
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions diracx-routers/src/diracx/routers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
logger = logging.getLogger(__name__)


DIRACX_MIN_CLIENT_VERSION = "0.0.1"
DIRACX_MIN_CLIENT_VERSION = "0.0.1a1"

###########################################3

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 2e3e230

Please sign in to comment.