Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of errors in aliases CSV upload #1838

Merged
merged 2 commits into from
Nov 5, 2024
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
1 change: 1 addition & 0 deletions news/1837.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
URL Management control panel: Fix error handling in CSV upload. @davisagli
10 changes: 10 additions & 0 deletions src/plone/restapi/services/aliases/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,22 @@ def _reply_csv(self):
raise BadRequest("Uploaded file is not a valid CSV file")

controlpanel = RedirectsControlPanel(self.context, self.request)
csv_errors = controlpanel.csv_errors = []
storage = getUtility(IRedirectionStorage)
status = IStatusMessage(self.request)
portal = getSite()
controlpanel.upload(file, portal, storage, status)
file.close()

if csv_errors:
self.request.response.setHeader("Content-Type", "application/json")
self.request.response.setStatus(BadRequest)
return {
"type": "BadRequest",
"message": f"Found {len(csv_errors)} errors in CSV file.",
# Skip first item which is a notice about the delimiter
"csv_errors": csv_errors[1:],
}
if err := status.show():
if err[0].type == "error":
raise BadRequest(err[0].message)
Expand Down
Loading