Skip to content

Commit ddba53b

Browse files
committed
🥅 Better error message for streaming text generation
1 parent 6147db5 commit ddba53b

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

‎packages/inference/src/HfInference.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,6 +1038,13 @@ export class HfInference {
10381038
});
10391039
}
10401040
if (!response.ok) {
1041+
if (response.headers.get("Content-Type")?.startsWith("application/json")) {
1042+
const output = await response.json();
1043+
if (output.error) {
1044+
throw new Error(output.error);
1045+
}
1046+
}
1047+
10411048
throw new Error(`Server response contains error: ${response.status}`);
10421049
}
10431050
if (response.headers.get("content-type") !== "text/event-stream") {

0 commit comments

Comments
 (0)