From 8fcf0764e5feed27627bc137caf90f1ee9e766aa Mon Sep 17 00:00:00 2001 From: Jing Hua Date: Thu, 9 Mar 2023 07:07:50 +0800 Subject: [PATCH] fix: stream lock bug Fixes #38 --- src/api/freeApi.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/api/freeApi.ts b/src/api/freeApi.ts index 135cfc6..742fd72 100644 --- a/src/api/freeApi.ts +++ b/src/api/freeApi.ts @@ -44,13 +44,15 @@ export const getChatCompletionStream = async ( 'Message from freechatgpt.chat:\nInvalid API endpoint! We recommend you to check your free API endpoint.' ); - 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); + if (response.status === 429 || !response.ok) { + const text = await response.text(); + let error = text; + if (text.includes('insufficient_quota')) { + error += + '\nMessage from freechatgpt.chat:\nWe recommend changing your API endpoint or API key'; + } + throw new Error(error); + } const stream = response.body; return stream;