fix: stream lock bug

Fixes #38
This commit is contained in:
Jing Hua 2023-03-09 07:07:50 +08:00
parent 6a3a154501
commit 8fcf0764e5

View file

@ -44,13 +44,15 @@ export const getChatCompletionStream = async (
'Message from freechatgpt.chat:\nInvalid API endpoint! We recommend you to check your free API endpoint.' '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 || !response.ok) {
if (response.status === 429 && text.includes('insufficient_quota')) const text = await response.text();
throw new Error( let error = text;
text + if (text.includes('insufficient_quota')) {
'\nMessage from freechatgpt.chat:\nWe recommend changing your API endpoint or API key' error +=
); '\nMessage from freechatgpt.chat:\nWe recommend changing your API endpoint or API key';
if (!response.ok) throw new Error(text); }
throw new Error(error);
}
const stream = response.body; const stream = response.body;
return stream; return stream;