Skip to content

Commit

Permalink
fix: fix undefined message in errors (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot authored and rattrayalex committed Jul 29, 2023
1 parent b27cfe9 commit 5714a14
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,22 @@ export class APIError extends Error {
message: string | undefined,
headers: Headers | undefined,
) {
super(message || (error as any)?.message || 'Unknown error occurred.');
super(APIError.makeMessage(error, message));
this.status = status;
this.headers = headers;
this.error = error;
}

private static makeMessage(error: any, message: string | undefined) {
return (
error?.message ?
typeof error.message === 'string' ? error.message
: JSON.stringify(error.message)
: error ? JSON.stringify(error)
: message || 'Unknown error occurred'
);
}

static generate(
status: number | undefined,
errorResponse: Object | undefined,
Expand Down

0 comments on commit 5714a14

Please sign in to comment.