return detail error from api call. (#295)

This commit is contained in:
ryanhex53
2023-03-30 17:53:24 +08:00
committed by GitHub
parent 4d7adf477a
commit 3631a5ac75
+6 -5
View File
@@ -34,14 +34,15 @@ export const OpenAIStream = async (
}),
});
if (res.status !== 200) {
const statusText = res.statusText;
throw new Error(`OpenAI API returned an error: ${statusText}`);
}
const encoder = new TextEncoder();
const decoder = new TextDecoder();
if (res.status !== 200) {
const statusText = res.statusText;
const result = await res.body?.getReader().read();
throw new Error(`OpenAI API returned an error: ${decoder.decode(result?.value) || statusText}`);
}
const stream = new ReadableStream({
async start(controller) {
const onParse = (event: ParsedEvent | ReconnectInterval) => {