Skip to content

Commit

Permalink
feat(errors): add status code to error message (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot authored and cleb11 committed Sep 19, 2023
1 parent ac9b156 commit 84481e1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ export abstract class APIClient {
return this.retryRequest(options, retriesRemaining, responseHeaders);
}

const errText = await response.text().catch(() => 'Unknown');
const errText = await response.text().catch((e) => castToError(e).message);
const errJSON = safeJSON(errText);
const errMessage = errJSON ? undefined : errText;

Expand Down
4 changes: 2 additions & 2 deletions src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class APIError extends Error {
message: string | undefined,
headers: Headers | undefined,
) {
super(APIError.makeMessage(error, message));
super(`${status} ${APIError.makeMessage(error, message)}`);
this.status = status;
this.headers = headers;
this.error = error;
Expand All @@ -25,7 +25,7 @@ export class APIError extends Error {
typeof error.message === 'string' ? error.message
: JSON.stringify(error.message)
: error ? JSON.stringify(error)
: message || 'Unknown error occurred'
: message || 'status code (no body)'
);
}

Expand Down

0 comments on commit 84481e1

Please sign in to comment.