diff --git a/src/core.ts b/src/core.ts index acf3bd33b..3a473ca61 100644 --- a/src/core.ts +++ b/src/core.ts @@ -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; diff --git a/src/error.ts b/src/error.ts index d2c337424..39f91b229 100644 --- a/src/error.ts +++ b/src/error.ts @@ -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; @@ -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)' ); }