Skip to content

Commit 4ac77f2

Browse files
authored
chore(api): Rework the way we handle errors on url precheck (#117)
1 parent 5d3c8bb commit 4ac77f2

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

bases/ecoindex/backend/routers/tasks.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,11 @@ async def add_ecoindex_analysis_task(
7070
try:
7171
r = requests.head(url=web_page.url, timeout=5)
7272
r.raise_for_status()
73-
except Exception:
73+
except requests.exceptions.RequestException as e:
7474
raise HTTPException(
75-
status_code=521,
75+
status_code=e.response.status_code
76+
if e.response
77+
else status.HTTP_400_BAD_REQUEST,
7678
detail=f"The URL {web_page.url} is unreachable. Are you really sure of this url? 🤔",
7779
)
7880

0 commit comments

Comments
 (0)