forked from XiaoMo/ChatGPT-Next-Web
fixup: add more error info
This commit is contained in:
parent
aed6b34950
commit
71cbf86b2c
@ -43,8 +43,7 @@ export function auth(req: NextRequest) {
|
||||
if (serverConfig.needCode && !serverConfig.codes.has(hashedCode) && !token) {
|
||||
return {
|
||||
error: true,
|
||||
needAccessCode: true,
|
||||
msg: "Please go settings page and fill your access code.",
|
||||
msg: !accessCode ? "empty access code" : "wrong access code",
|
||||
};
|
||||
}
|
||||
|
||||
@ -58,7 +57,7 @@ export function auth(req: NextRequest) {
|
||||
console.log("[Auth] admin did not provide an api key");
|
||||
return {
|
||||
error: true,
|
||||
msg: "Empty Api Key",
|
||||
msg: "admin did not provide an api key",
|
||||
};
|
||||
}
|
||||
} else {
|
||||
|
@ -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();
|
||||
}
|
||||
},
|
||||
|
@ -296,9 +296,7 @@ export const useChatStore = create<ChatStore>()(
|
||||
botMessage.content !== Locale.Error.Unauthorized &&
|
||||
!isAborted
|
||||
) {
|
||||
botMessage.content += "\n\n" + Locale.Store.Error;
|
||||
} else if (botMessage.content.length === 0) {
|
||||
botMessage.content = prettyObject(error);
|
||||
botMessage.content += "\n\n" + prettyObject(error);
|
||||
}
|
||||
botMessage.streaming = false;
|
||||
userMessage.isError = !isAborted;
|
||||
|
Loading…
Reference in New Issue
Block a user