Skip to content

Commit

Permalink
feat: generic error message handling
Browse files Browse the repository at this point in the history
  • Loading branch information
joao-conde committed Nov 29, 2023
1 parent b301a8a commit 7ffb9b8
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions js/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,15 @@ export class API extends mix(BaseAPI).with(

async _handleResponse(response, errorMessage = "Problem in request") {
const result = await this._getResult(response);
const errors =
result.response && result.response.errors
? result.response.errors.map(error => JSON.stringify(error)).join(",")
: null;
verify(!errors, errors, response.status || 500);
verify(!result.Fault, result.error || errorMessage, response.status || 500);
verify(response.ok, result.error || errorMessage, response.status || 500);
if (!response.ok) {
let error = null;
try {
error = JSON.stringify(result);
} catch {
error = errorMessage;
}
throw new OperationalError(error, response.status || 500);
}
return result;
}

Expand Down

0 comments on commit 7ffb9b8

Please sign in to comment.