-
Notifications
You must be signed in to change notification settings - Fork 883
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(client): correctly handle errors during streaming #379
Conversation
} catch (e) { | ||
console.error(`Could not parse message into JSON:`, sse.data); | ||
console.error(`From chunk:`, sse.raw); | ||
throw e; | ||
} | ||
|
||
if (data && data.error) { | ||
throw new APIError(undefined, data.error, undefined, undefined); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we're not setting the APIError.message
here, is that intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I was under the impression that the API error data will include a message
property. That property will then be used by the APIError
class if a message isn't explicitly passed in the constructor. If the message property isn't set, then we'll default to stringifying the error object to raw JSON.
Is that assumption correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The assumption is correct, but I don't see code in APIError
to assign message
from the error object:
Lines 16 to 41 in 6484039
constructor( | |
status: number | undefined, | |
error: Object | undefined, | |
message: string | undefined, | |
headers: Headers | undefined, | |
) { | |
super(`${status} ${APIError.makeMessage(error, message)}`); | |
this.status = status; | |
this.headers = headers; | |
const data = error as Record<string, any>; | |
this.error = data; | |
this.code = data?.['code']; | |
this.param = data?.['param']; | |
this.type = data?.['type']; | |
} | |
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 || 'status code (no body)' | |
); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's this line
Line 36 in 6484039
typeof error.message === 'string' ? error.message |
The error
argument there is the data that the API responded with
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see, thanks!
When status is undefined, should we skip the space in the error message here?
Line 22 in 6484039
super(`${status} ${APIError.makeMessage(error, message)}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah we can probably clean that up; I'll file a ticket
No description provided.