From a3e05c2b704e208359e3eb37667634d9dc6daa90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ali=20Gen=C3=A7ay?= Date: Thu, 23 Feb 2023 04:14:08 -0800 Subject: [PATCH] Write the underlying exception details to streamed response Currently, when stream is enabled the `fetchSSE` isn't returning the api response details. --- src/fetch-sse.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/fetch-sse.ts b/src/fetch-sse.ts index 00410eb..c49f655 100644 --- a/src/fetch-sse.ts +++ b/src/fetch-sse.ts @@ -12,7 +12,8 @@ export async function fetchSSE( const { onMessage, ...fetchOptions } = options const res = await fetch(url, fetchOptions) if (!res.ok) { - const msg = `ChatGPT error ${res.status || res.statusText}` + const reason = await res.text() + const msg = `ChatGPT error ${res.status || res.statusText}: ${reason}` const error = new types.ChatGPTError(msg, { cause: res }) error.statusCode = res.status error.statusText = res.statusText