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); }