Skip to content

Commit 77b4f84

Browse files
authored
🥅 Better error handling for chatCompletion (huggingface#1080)
Thanks @chelsey-datasaur for the report. Fix huggingface#1079 cc @SBrandeis @hanouticelina for viz, as it handles messages from `chatCompletion`
1 parent 74680a1 commit 77b4f84

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

‎packages/inference/src/tasks/custom/streamingRequest.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,16 @@ export async function* streamingRequest<T>(
7979
}
8080
const data = JSON.parse(event.data);
8181
if (typeof data === "object" && data !== null && "error" in data) {
82-
throw new Error(data.error);
82+
const errorStr =
83+
typeof data.error === "string"
84+
? data.error
85+
: typeof data.error === "object" &&
86+
data.error &&
87+
"message" in data.error &&
88+
typeof data.error.message === "string"
89+
? data.error.message
90+
: JSON.stringify(data.error);
91+
throw new Error(`Error forwarded from backend: ` + errorStr);
8392
}
8493
yield data as T;
8594
}

0 commit comments

Comments
 (0)