From 7c43c67b3dff812dd566f0656cc69b7d256fd086 Mon Sep 17 00:00:00 2001 From: Damir Modyarov Date: Sun, 12 May 2024 19:08:45 +0300 Subject: [PATCH] fix: Add debug error for streaming fail --- src/request.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/request.ts b/src/request.ts index 378e8f6..99633aa 100644 --- a/src/request.ts +++ b/src/request.ts @@ -70,8 +70,12 @@ export const fetchStream = async (url: string) => { const data = await fetch(url) if (!data.ok) { - const error = await data.json() as unknown - return genericErrorSchema.parse(error) + const error = await data.json().catch(() => null) as unknown + const body = genericErrorSchema.safeParse(error) + if (!body.success) { + throw new Error(`streaming from ${new URL(url).host} failed`) + } + return body.data } const contentDisposition = data.headers.get("Content-Disposition")