diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 8cdf217..0000000 Binary files a/.DS_Store and /dev/null differ diff --git a/src/api.ts b/src/api.ts index 8eb496e..08d9f4c 100644 --- a/src/api.ts +++ b/src/api.ts @@ -107,13 +107,24 @@ export async function requestApi( // Check if response is chunked const transferEncoding = res.headers.get('transfer-encoding'); if (transferEncoding === 'chunked') { - // Handle streaming response - const reader = res.body?.getReader(); + // Handle streaming response, if a reader is present + const reader = typeof res.body?.getReader === 'function' ? res.body.getReader() : null; if (!reader) { - return { - success: false, - err: new Error('No readable stream available'), - }; + try { + const text = await res.text(); + try { + const value = JSON.parse(text); + return { success: true, value }; + } catch (e) { + // Return if just a normal string + return { success: true, value: { text } as any }; + } + } catch (e) { + return { + success: false, + err: new Error('No readable stream available and cant parse'), + }; + } } let chunks: any = '';