From 9c577ad9d57d47ad5831ca15f15988ba0381ee2c Mon Sep 17 00:00:00 2001 From: lloydzhou Date: Tue, 1 Oct 2024 12:55:57 +0800 Subject: [PATCH] hotfix for plugin runtime --- app/utils.ts | 9 ++++++--- app/utils/chat.ts | 5 ++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/utils.ts b/app/utils.ts index c1476152a..95880115a 100644 --- a/app/utils.ts +++ b/app/utils.ts @@ -320,9 +320,12 @@ export function adapter(config: Record) { const fetchUrl = params ? `${path}?${new URLSearchParams(params as any).toString()}` : path; - return fetch(fetchUrl as string, { ...rest, responseType: "text" }) - .then((res) => res.text()) - .then((data) => ({ data })); + return fetch(fetchUrl as string, { ...rest, responseType: "text" }).then( + (res) => { + const { status, headers } = res; + return res.text().then((data) => ({ status, headers, data })); + }, + ); } export function safeLocalStorage(): { diff --git a/app/utils/chat.ts b/app/utils/chat.ts index 254cef401..3d7960480 100644 --- a/app/utils/chat.ts +++ b/app/utils/chat.ts @@ -222,7 +222,10 @@ export function stream( ), ) .then((res) => { - const content = JSON.stringify(res.data); + let content = res.data; + try { + content = JSON.stringify(res.data); + } catch (e) {} if (res.status >= 300) { return Promise.reject(content); }