From 8aaa0d19b1d56b434693134d2f9f471e49d25c72 Mon Sep 17 00:00:00 2001 From: coyotte508 Date: Wed, 18 Dec 2024 13:47:15 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A5=85=20Better=20error=20handling=20for?= =?UTF-8?q?=20chatCompletion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../inference/src/tasks/custom/streamingRequest.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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; }