From 7dbb2a9e82ee0f2d036da8f10b046fe7450fa0ff Mon Sep 17 00:00:00 2001 From: Michael Romashov Date: Sun, 17 Mar 2024 12:09:00 -0400 Subject: [PATCH] better error logging for fetch --- src/utils/fetch.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/fetch.ts b/src/utils/fetch.ts index 2994f7c..14673e2 100644 --- a/src/utils/fetch.ts +++ b/src/utils/fetch.ts @@ -40,7 +40,7 @@ export async function fetchApi(route: string, config?: NextFet return fetch(`${process.env.NEXT_PUBLIC_API_URL}/api${route}`, { ...config, headers }) .then(async (resp) => { if (!resp.ok) { - return Promise.reject(resp); + return Promise.reject(new Error(`${resp.url}: ${resp.status} ${resp.statusText}`)); } if (resp.headers.get('Content-Type') === 'application/json') {