From cc1d5b09de32f92610bbf94284282b8d91a0b2a5 Mon Sep 17 00:00:00 2001 From: Muspi Merol Date: Sat, 24 Aug 2024 03:08:34 +0800 Subject: [PATCH] chore: raise error when fail to chat with LLM --- src/lib/chat.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lib/chat.ts b/src/lib/chat.ts index cf183dd..5e832a4 100644 --- a/src/lib/chat.ts +++ b/src/lib/chat.ts @@ -4,5 +4,9 @@ import { responseToAsyncIterator } from "./utils/iter"; export default async function* (options: ChatCompletionCreateParams) { const res = await fetch("/api/chat", { method: "POST", body: JSON.stringify(options), headers: { "content-type": "application/json" } }); + if (res.status !== 200) { + console.error(await res.text()); + throw new Error(`Failed to fetch: ${res.status} ${res.statusText}`); + } yield * responseToAsyncIterator(res); }