Skip to content

Commit

Permalink
Backport of UI: Handle error from ResponseWithStatusCode (#23116)
Browse files Browse the repository at this point in the history
Co-authored-by: Chelsea Shaw <82459713+hashishaw@users.noreply.github.com>
  • Loading branch information
1 parent 79cd74d commit ac08ecb
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion ui/app/adapters/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand Down

0 comments on commit ac08ecb

Please sign in to comment.