chore: fix error message and readable message for openai key missing

This commit is contained in:
Tianzhou Chen
2023-05-02 01:46:06 +08:00
parent bf37d766bc
commit f3476d8d91
2 changed files with 10 additions and 2 deletions

View File

@ -218,8 +218,7 @@ const ConversationView = () => {
let errorMessage =
"Failed to request message, please check your network.";
try {
const res = await rawRes.json();
errorMessage = res.error.message;
errorMessage = await rawRes.statusText;
} catch (error) {
// do nth
}

View File

@ -30,6 +30,15 @@ const handler = async (req: NextRequest) => {
const reqBody = await req.json();
const openAIApiConfig = reqBody.openAIApiConfig;
const apiKey = openAIApiConfig?.key || openAIApiKey;
if (!apiKey) {
return new Response("Unauthorized", {
status: 401,
statusText:
"OpenAI API Key is missing. You can supply your own key via Settings.",
});
}
const apiEndpoint = getApiEndpoint(
openAIApiConfig?.endpoint || openAIApiEndpoint
);