From ac08ecb7fb4271b02f43dea3cc3ea10ad03a254e Mon Sep 17 00:00:00 2001 From: hc-github-team-secure-vault-core <82990506+hc-github-team-secure-vault-core@users.noreply.github.com> Date: Fri, 15 Sep 2023 16:38:22 -0400 Subject: [PATCH] Backport of UI: Handle error from ResponseWithStatusCode (#23116) Co-authored-by: Chelsea Shaw <82459713+hashishaw@users.noreply.github.com> --- ui/app/adapters/application.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ui/app/adapters/application.js b/ui/app/adapters/application.js index ae92adc6ba..7f977fd8c2 100644 --- a/ui/app/adapters/application.js +++ b/ui/app/adapters/application.js @@ -119,10 +119,18 @@ export default RESTAdapter.extend({ handleResponse(status, headers, payload, requestData) { const returnVal = this._super(...arguments); - // ember data errors don't have the status code, so we add it here if (returnVal instanceof AdapterError) { + // ember data errors don't have the status code, so we add it here set(returnVal, 'httpStatus', status); set(returnVal, 'path', requestData.url); + // Most of the time when the Vault API returns an error, the payload looks like: + // { errors: ['some error message']} + // But sometimes (eg RespondWithStatusCode) it looks like this: + // { data: { error: 'some error message' } } + if (payload?.data?.error && !payload.errors) { + // Normalize the errors from RespondWithStatusCode + set(returnVal, 'errors', [payload.data.error]); + } } return returnVal; },