Skip to content

Commit

Permalink
feat(errors): add status code to error message (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot committed Sep 15, 2023
1 parent 429d8f4 commit 76cf128
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
Expand Up @@ -377,7 +377,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
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 76cf128

Please sign in to comment.