From 98729351e0610a6d2554bc2bf33e0ed1dde7d5ab Mon Sep 17 00:00:00 2001 From: Jing Hua Date: Tue, 7 Mar 2023 07:35:10 +0800 Subject: [PATCH] error message for insufficient quota --- src/api/freeApi.ts | 8 +++++++- src/components/Chat/ChatContent/ChatContent.tsx | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/api/freeApi.ts b/src/api/freeApi.ts index 67dbf15..bb372ac 100644 --- a/src/api/freeApi.ts +++ b/src/api/freeApi.ts @@ -39,7 +39,13 @@ export const getChatCompletionStream = async ( stream: true, }), }); - if (!response.ok) throw new Error(await response.text()); + const text = await response.text(); + if (response.status === 429 && text.includes('insufficient_quota')) + throw new Error( + text + + '\nMessage from freechatgpt.chat:\nWe recommend changing your API endpoint or API key' + ); + if (!response.ok) throw new Error(text); const stream = response.body; return stream; diff --git a/src/components/Chat/ChatContent/ChatContent.tsx b/src/components/Chat/ChatContent/ChatContent.tsx index 4c7a398..9b091fc 100644 --- a/src/components/Chat/ChatContent/ChatContent.tsx +++ b/src/components/Chat/ChatContent/ChatContent.tsx @@ -60,8 +60,8 @@ const ChatContent = () => { /> {error !== '' && ( -
-
+
+
{error}