diff --git a/packages/inference/src/tasks/custom/streamingRequest.ts b/packages/inference/src/tasks/custom/streamingRequest.ts index 7f4179811..c955fa50d 100644 --- a/packages/inference/src/tasks/custom/streamingRequest.ts +++ b/packages/inference/src/tasks/custom/streamingRequest.ts @@ -77,7 +77,16 @@ export async function* streamingRequest( } 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; }