From bb1377445cfbeaabaf9eaef1c27f8c4d6377045d Mon Sep 17 00:00:00 2001 From: Travis Fischer Date: Tue, 28 Feb 2023 04:02:46 -0600 Subject: [PATCH] =?UTF-8?q?=E2=9A=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- legacy/src/fetch-sse.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/legacy/src/fetch-sse.ts b/legacy/src/fetch-sse.ts index c49f6552..1900efa8 100644 --- a/legacy/src/fetch-sse.ts +++ b/legacy/src/fetch-sse.ts @@ -12,8 +12,15 @@ export async function fetchSSE( const { onMessage, ...fetchOptions } = options const res = await fetch(url, fetchOptions) if (!res.ok) { - const reason = await res.text() - const msg = `ChatGPT error ${res.status || res.statusText}: ${reason}` + let reason: string + + try { + reason = await res.text() + } catch (err) { + reason = res.statusText + } + + const msg = `ChatGPT error ${res.status}: ${reason}` const error = new types.ChatGPTError(msg, { cause: res }) error.statusCode = res.status error.statusText = res.statusText