Handle create-user 500 responses where body contains 'message' instead of 'error'#7946
Handle create-user 500 responses where body contains 'message' instead of 'error'#7946
Conversation
…d of 'error' When the server returns HTTP 500 during user creation (for example due to an SMTP MailHost error), the response body may not include an 'error' key and instead contains a top-level 'message'. This caused a runtime TypeError when trying to read 'response.body.error.message'. This change makes the client tolerant of that shape by extracting 'response.body.message' when 'response.body.error' is absent, falling back to other error fields. It prevents reading properties of undefined and ensures a readable error string is shown to the user.
There was a problem hiding this comment.
Thanks.
I think the root of the problem here is that the @users endpoint was using a non-standard way of serializing errors (https://github.com/plone/plone.restapi/blob/main/src/plone/restapi/services/users/add.py#L291) -- which uses "error" -- instead of raising an exception and letting it get serialized by the exception view in plone.rest (https://github.com/plone/plone.rest/blob/main/src/plone/rest/errors.py) -- which uses "message"
We should update the users service to raise exceptions the standard way. But in order to do that smoothly we have to accept both ways here, so this is good.
I'm making a suggestion to move this into helpers so we can use it from other places in Volto too. I'll let you decide whether to do that or merge it as is.
* main: (122 commits) Release 19.0.0-alpha.27 Release @plone/slate 19.0.0-alpha.12 Release @plone/razzle 1.0.0-alpha.1 We do not release @plone/client from here Handle create-user 500 responses where body contains 'message' instead of 'error' (#7946) Dropzone filewidget a11y (#7956) Update css-minimizer-webpack-plugin to v7 and keep razzleOptions.enableSourceMaps control (#7934) Refactor Password Reset: Convert Class-Based Component to Functional Component (#7697) fix: Fixed searchable types in Object Browser Widget, adding also sel… (#7942) Fix in-page drag-and-drop for the Listing block in Volto 18 and 19 (#7907) Improved docs of Plone REST API JavaScript Client (#5576) Fix Moderate Comments control panel visibility based on Discussion Support addon installation (#7878) fix: Add authorization error handling to control panels (#7807) Fix subordering order tab (#7937) (#7939) Fix converting value to html in HtmlSlateWidget (#7938) razzle.config.js: Fix defaultPlugins missing name property to enable addon SCSS plugin replacement (#7908) Update users controlpanel to work with new response format (#7895) Avoid storing blocksClipboard in localstorage until it has a value (#7925) Remove link to Jobfamilie MEDICE: site is no longer a Volto site (redirects to non-Volto destination) (#7929) Exclude `.storybook` from ESLint's default hidden directory ignore list via `.eslintignore` to allow linting of Storybook configuration files (#7898) ...
When the server returns HTTP 500 during user creation (for example due to an SMTP MailHost error), the response body may not include an 'error' key and instead contains a top-level 'message'. This caused a runtime TypeError when trying to read 'response.body.error.message'.
This change makes the client tolerant of that shape by extracting 'response.body.message' when 'response.body.error' is absent, falling back to other error fields. It prevents reading properties of undefined and ensures a readable error string is shown to the user.