Skip to content

Commit 1ebdda8

Browse files
authored
🐛(backend) Fix unreachable exception handler for URLValidator
The exception block was never being executed because URLValidator raises django.core.exceptions.ValidationError, not drf.exceptions.ValidationError, so the except block was dead code. Signed-off-by: Mohamed El Amine BOUKERFA <boukerfa.ma@gmail.com>
1 parent d0bf24f commit 1ebdda8

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

src/backend/core/api/viewsets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2135,7 +2135,7 @@ def cors_proxy(self, request, *args, **kwargs):
21352135
url_validator = URLValidator(schemes=["http", "https"])
21362136
try:
21372137
url_validator(url)
2138-
except drf.exceptions.ValidationError as e:
2138+
except ValidationError as e:
21392139
return drf.response.Response(
21402140
{"detail": str(e)},
21412141
status=drf.status.HTTP_400_BAD_REQUEST,

src/backend/core/tests/documents/test_api_documents_cors_proxy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def test_api_docs_cors_proxy_invalid_url(url_to_fetch):
255255
f"/api/v1.0/documents/{document.id!s}/cors-proxy/?url={url_to_fetch}"
256256
)
257257
assert response.status_code == 400
258-
assert response.json() == ["Enter a valid URL."]
258+
assert response.json() == {"detail": "['Enter a valid URL.']"}
259259

260260

261261
@unittest.mock.patch("core.api.viewsets.socket.getaddrinfo")

0 commit comments

Comments
 (0)