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) {
|
if (serverConfig.needCode && !serverConfig.codes.has(hashedCode) && !token) {
|
||||||
return {
|
return {
|
||||||
error: true,
|
error: true,
|
||||||
needAccessCode: true,
|
msg: !accessCode ? "empty access code" : "wrong access code",
|
||||||
msg: "Please go settings page and fill your access code.",
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,7 +57,7 @@ export function auth(req: NextRequest) {
|
|||||||
console.log("[Auth] admin did not provide an api key");
|
console.log("[Auth] admin did not provide an api key");
|
||||||
return {
|
return {
|
||||||
error: true,
|
error: true,
|
||||||
msg: "Empty Api Key",
|
msg: "admin did not provide an api key",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -4,6 +4,7 @@ import { useAccessStore, useAppConfig, useChatStore } from "@/app/store";
|
|||||||
import { ChatOptions, getHeaders, LLMApi, LLMUsage } from "../api";
|
import { ChatOptions, getHeaders, LLMApi, LLMUsage } from "../api";
|
||||||
import Locale from "../../locales";
|
import Locale from "../../locales";
|
||||||
import { fetchEventSource } from "@microsoft/fetch-event-source";
|
import { fetchEventSource } from "@microsoft/fetch-event-source";
|
||||||
|
import { prettyObject } from "@/app/utils/format";
|
||||||
|
|
||||||
export class ChatGPTApi implements LLMApi {
|
export class ChatGPTApi implements LLMApi {
|
||||||
public ChatPath = "v1/chat/completions";
|
public ChatPath = "v1/chat/completions";
|
||||||
@ -72,12 +73,24 @@ export class ChatGPTApi implements LLMApi {
|
|||||||
options.onFinish(responseText);
|
options.onFinish(responseText);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
controller.signal.onabort = finish;
|
||||||
|
|
||||||
fetchEventSource(chatPath, {
|
fetchEventSource(chatPath, {
|
||||||
...chatPayload,
|
...chatPayload,
|
||||||
async onopen(res) {
|
async onopen(res) {
|
||||||
clearTimeout(reqestTimeoutId);
|
clearTimeout(reqestTimeoutId);
|
||||||
if (res.status === 401) {
|
if (res.status === 401) {
|
||||||
|
let extraInfo = { error: undefined };
|
||||||
|
try {
|
||||||
|
extraInfo = await res.clone().json();
|
||||||
|
} catch {}
|
||||||
|
|
||||||
responseText += "\n\n" + Locale.Error.Unauthorized;
|
responseText += "\n\n" + Locale.Error.Unauthorized;
|
||||||
|
|
||||||
|
if (extraInfo.error) {
|
||||||
|
responseText += "\n\n" + prettyObject(extraInfo);
|
||||||
|
}
|
||||||
|
|
||||||
return finish();
|
return finish();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -296,9 +296,7 @@ export const useChatStore = create<ChatStore>()(
|
|||||||
botMessage.content !== Locale.Error.Unauthorized &&
|
botMessage.content !== Locale.Error.Unauthorized &&
|
||||||
!isAborted
|
!isAborted
|
||||||
) {
|
) {
|
||||||
botMessage.content += "\n\n" + Locale.Store.Error;
|
botMessage.content += "\n\n" + prettyObject(error);
|
||||||
} else if (botMessage.content.length === 0) {
|
|
||||||
botMessage.content = prettyObject(error);
|
|
||||||
}
|
}
|
||||||
botMessage.streaming = false;
|
botMessage.streaming = false;
|
||||||
userMessage.isError = !isAborted;
|
userMessage.isError = !isAborted;
|
||||||
|
Loading…
Reference in New Issue
Block a user