Skip to content

Commit 9341219

Browse files
feat(errors): add status code to error message (#315)
1 parent f52b3f5 commit 9341219

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/core.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ export abstract class APIClient {
377377
return this.retryRequest(options, retriesRemaining, responseHeaders);
378378
}
379379

380-
const errText = await response.text().catch(() => 'Unknown');
380+
const errText = await response.text().catch((e) => castToError(e).message);
381381
const errJSON = safeJSON(errText);
382382
const errMessage = errJSON ? undefined : errText;
383383

src/error.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class APIError extends Error {
1717
message: string | undefined,
1818
headers: Headers | undefined,
1919
) {
20-
super(APIError.makeMessage(error, message));
20+
super(`${status} ${APIError.makeMessage(error, message)}`);
2121
this.status = status;
2222
this.headers = headers;
2323

@@ -34,7 +34,7 @@ export class APIError extends Error {
3434
typeof error.message === 'string' ? error.message
3535
: JSON.stringify(error.message)
3636
: error ? JSON.stringify(error)
37-
: message || 'Unknown error occurred'
37+
: message || 'status code (no body)'
3838
);
3939
}
4040

0 commit comments

Comments
 (0)