Skip to content

Commit

Permalink
fix: improve status code in error messages (#381)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot authored Oct 16, 2023
1 parent 689db0b commit 68dfb17
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,23 @@ export class APIError extends OpenAIError {
}

private static makeMessage(status: number | undefined, error: any, message: string | undefined) {
return (
(status || '') +
(error?.message ?
const msg =
error?.message ?
typeof error.message === 'string' ? error.message
: JSON.stringify(error.message)
: error ? JSON.stringify(error)
: message || 'status code (no body)')
);
: message;

if (status && msg) {
return `${status} ${msg}`;
}
if (status) {
return `${status} status code (no body)`;
}
if (msg) {
return msg;
}
return '(no status code or body)';
}

static generate(
Expand Down

0 comments on commit 68dfb17

Please sign in to comment.