diff --git a/app/utils.ts b/app/utils.ts index 4887a1021..9f5dd3150 100644 --- a/app/utils.ts +++ b/app/utils.ts @@ -293,9 +293,7 @@ export function fetch( options?: Record, ): Promise { if (window.__TAURI__) { - return tauriStreamFetch(url, options) - .then((res) => res.text()) - .then((data) => ({ data })); + return tauriStreamFetch(url, options); // const payload = options?.body || options?.data; // return tauriFetch(url, { // ...options, @@ -319,7 +317,9 @@ export function adapter(config: Record) { const fetchUrl = params ? `${path}?${new URLSearchParams(params as any).toString()}` : path; - return fetch(fetchUrl as string, { ...rest, responseType: "text" }); + return fetch(fetchUrl as string, { ...rest, responseType: "text" }) + .then((res) => res.text()) + .then((data) => ({ data })); } export function safeLocalStorage(): { diff --git a/app/utils/stream.ts b/app/utils/stream.ts index e8850fcba..2a8c13777 100644 --- a/app/utils/stream.ts +++ b/app/utils/stream.ts @@ -85,7 +85,15 @@ export function fetch(url: string, options?: RequestInit): Promise { .then((res: StreamResponse) => { request_id = res.request_id; const { status, status_text: statusText, headers } = res; - return new Response(ts.readable, { status, statusText, headers }); + const response = new Response(ts.readable, { + status, + statusText, + headers, + }); + if (status >= 300) { + setTimeout(close, 50); + } + return response; }) .catch((e) => { console.error("stream error", e);