From 3fc8a3fc034efe5fa61a29343b02e1e847740bc3 Mon Sep 17 00:00:00 2001 From: Vincent Vatelot Date: Tue, 18 Mar 2025 11:39:35 +0000 Subject: [PATCH] chore(api): Rework the way we handle errors on url precheck --- bases/ecoindex/backend/routers/tasks.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bases/ecoindex/backend/routers/tasks.py b/bases/ecoindex/backend/routers/tasks.py index 0d0e0ee..3d74453 100644 --- a/bases/ecoindex/backend/routers/tasks.py +++ b/bases/ecoindex/backend/routers/tasks.py @@ -70,9 +70,11 @@ async def add_ecoindex_analysis_task( try: r = requests.head(url=web_page.url, timeout=5) r.raise_for_status() - except Exception: + except requests.exceptions.RequestException as e: raise HTTPException( - status_code=521, + status_code=e.response.status_code + if e.response + else status.HTTP_400_BAD_REQUEST, detail=f"The URL {web_page.url} is unreachable. Are you really sure of this url? 🤔", )