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 = let errorMessage =
"Failed to request message, please check your network."; "Failed to request message, please check your network.";
try { try {
const res = await rawRes.json(); errorMessage = await rawRes.statusText;
errorMessage = res.error.message;
} catch (error) { } catch (error) {
// do nth // do nth
} }

View File

@ -30,6 +30,15 @@ const handler = async (req: NextRequest) => {
const reqBody = await req.json(); const reqBody = await req.json();
const openAIApiConfig = reqBody.openAIApiConfig; const openAIApiConfig = reqBody.openAIApiConfig;
const apiKey = openAIApiConfig?.key || openAIApiKey; 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( const apiEndpoint = getApiEndpoint(
openAIApiConfig?.endpoint || openAIApiEndpoint openAIApiConfig?.endpoint || openAIApiEndpoint
); );