From ed7226a83e5221de6ae52f7f0aa9c01182568be6 Mon Sep 17 00:00:00 2001 From: Martin Schmidt Date: Tue, 24 Sep 2024 16:41:46 +0200 Subject: [PATCH] fix: properly handle request errors --- plugins/typescript/src/templates/fetcher.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/plugins/typescript/src/templates/fetcher.ts b/plugins/typescript/src/templates/fetcher.ts index d9170135..dbf3bf78 100644 --- a/plugins/typescript/src/templates/fetcher.ts +++ b/plugins/typescript/src/templates/fetcher.ts @@ -109,11 +109,8 @@ export async function ${camel(prefix)}Fetch< : "Unexpected error" }; } - - throw error; } - - if (response.headers.get('content-type')?.includes('json')) { + else if (response.headers.get('content-type')?.includes('json')) { return await response.json(); } else { // if it is not a json response, assume it is a blob and cast it to TData @@ -128,6 +125,7 @@ export async function ${camel(prefix)}Fetch< }; throw errorObject; } + throw error; } const resolveUrl = (