Skip to content

Commit

Permalink
feat(errors): add status code to error message (#315)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot authored Sep 15, 2023
1 parent f52b3f5 commit 9341219
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 @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,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;

Expand All @@ -34,7 +34,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 9341219

Please sign in to comment.