Skip to content

Commit

Permalink
Fix handling of errors in aliases CSV upload
Browse files Browse the repository at this point in the history
  • Loading branch information
davisagli committed Nov 5, 2024
1 parent e634169 commit e5acfc2
Showing 1 changed file with 10 additions and 0 deletions.
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

0 comments on commit e5acfc2

Please sign in to comment.