Skip to content

Commit

Permalink
🥅 Better error handling for chatCompletion (#1080)
Browse files Browse the repository at this point in the history
Thanks @chelsey-datasaur for the report.

Fix #1079 

cc @SBrandeis @hanouticelina for viz, as it handles messages from
`chatCompletion`
  • Loading branch information
coyotte508 authored Jan 13, 2025
1 parent 74680a1 commit 77b4f84
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/inference/src/tasks/custom/streamingRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,16 @@ export async function* streamingRequest<T>(
}
const data = JSON.parse(event.data);
if (typeof data === "object" && data !== null && "error" in data) {
throw new Error(data.error);
const errorStr =
typeof data.error === "string"
? data.error
: typeof data.error === "object" &&
data.error &&
"message" in data.error &&
typeof data.error.message === "string"
? data.error.message
: JSON.stringify(data.error);
throw new Error(`Error forwarded from backend: ` + errorStr);
}
yield data as T;
}
Expand Down

0 comments on commit 77b4f84

Please sign in to comment.