Skip to content

Commit

Permalink
fix: correctly handle errors with the missing response
Browse files Browse the repository at this point in the history
There is no response in case this is a timeout error.

Closes: #17
  • Loading branch information
tsufiev committed Jul 15, 2022
1 parent 75d5450 commit 6b9dc0e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,19 +180,28 @@ export default class AxiosWrapper {
this.clearRequestToken(concurrentId);
}

let errorResponse;
if (thrown.response) {
errorResponse = thrown.response;
} else if (typeof thrown.toJSON === 'function') {
errorResponse = thrown.toJSON();
} else {
errorResponse = thrown;
}

if (collectRequest) {
this.collectRequest({
...request,
requestStart,
response: thrown.response,
response: errorResponse,
error: true,
cancelled: axios.isCancel(thrown),
responseError: thrown,
});
}

return this.handleRequestError(
thrown.response,
errorResponse,
() => this.request({...methodParams, retries: retries + 1}),
retries,
new Error(thrown instanceof Error ? thrown.message : 'Unknown error'),
Expand Down

0 comments on commit 6b9dc0e

Please sign in to comment.