فهرست منبع

hotfix for plugin runtime

lloydzhou 1 سال پیش
والد
کامیت
9c577ad9d5
2فایلهای تغییر یافته به همراه10 افزوده شده و 4 حذف شده
  1. 6 3
      app/utils.ts
  2. 4 1
      app/utils/chat.ts

+ 6 - 3
app/utils.ts

@@ -320,9 +320,12 @@ export function adapter(config: Record<string, unknown>) {
   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(): {

+ 4 - 1
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);
                 }