fixup: add more error info

This commit is contained in:
Yidadaa
2023-05-16 01:58:58 +08:00
parent aed6b34950
commit 71cbf86b2c
3 changed files with 16 additions and 6 deletions

View File

@@ -4,6 +4,7 @@ import { useAccessStore, useAppConfig, useChatStore } from "@/app/store";
import { ChatOptions, getHeaders, LLMApi, LLMUsage } from "../api";
import Locale from "../../locales";
import { fetchEventSource } from "@microsoft/fetch-event-source";
import { prettyObject } from "@/app/utils/format";
export class ChatGPTApi implements LLMApi {
public ChatPath = "v1/chat/completions";
@@ -72,12 +73,24 @@ export class ChatGPTApi implements LLMApi {
options.onFinish(responseText);
};
controller.signal.onabort = finish;
fetchEventSource(chatPath, {
...chatPayload,
async onopen(res) {
clearTimeout(reqestTimeoutId);
if (res.status === 401) {
let extraInfo = { error: undefined };
try {
extraInfo = await res.clone().json();
} catch {}
responseText += "\n\n" + Locale.Error.Unauthorized;
if (extraInfo.error) {
responseText += "\n\n" + prettyObject(extraInfo);
}
return finish();
}
},