Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/backend/core/api/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2135,7 +2135,7 @@ def cors_proxy(self, request, *args, **kwargs):
url_validator = URLValidator(schemes=["http", "https"])
try:
url_validator(url)
except drf.exceptions.ValidationError as e:
except ValidationError as e:
return drf.response.Response(
{"detail": str(e)},
status=drf.status.HTTP_400_BAD_REQUEST,
Comment on lines +2138 to 2141
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Return structured validation details instead of a stringified list

On Line 2140, {"detail": str(e)} produces a list-as-string payload ("['Enter a valid URL.']"). Prefer a structured detail to keep the API stable and machine-friendly.

💡 Proposed change
-        except ValidationError as e:
+        except ValidationError as e:
             return drf.response.Response(
-                {"detail": str(e)},
+                {"detail": e.messages},
                 status=drf.status.HTTP_400_BAD_REQUEST,
             )
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
except ValidationError as e:
return drf.response.Response(
{"detail": str(e)},
status=drf.status.HTTP_400_BAD_REQUEST,
except ValidationError as e:
return drf.response.Response(
{"detail": e.messages},
status=drf.status.HTTP_400_BAD_REQUEST,
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/backend/core/api/viewsets.py` around lines 2138 - 2141, The exception
handler currently returns a stringified ValidationError via {"detail": str(e)};
change it to return structured validation data instead: extract the validation
payload from the exception (prefer e.message_dict if present, then e.messages,
then e.detail) and use that value as the "detail" in the drf.response.Response
so clients get machine-readable error structures; update the except block that
catches ValidationError in viewsets.py (the variable e and the
drf.response.Response call) to build and return this structured payload instead
of str(e).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def test_api_docs_cors_proxy_invalid_url(url_to_fetch):
f"/api/v1.0/documents/{document.id!s}/cors-proxy/?url={url_to_fetch}"
)
assert response.status_code == 400
assert response.json() == ["Enter a valid URL."]
assert response.json() == {"detail": "['Enter a valid URL.']"}


@unittest.mock.patch("core.api.viewsets.socket.getaddrinfo")
Expand Down
Loading