Skip to content

Commit

Permalink
better error logging for fetch
Browse files Browse the repository at this point in the history
MikeRomaa committed Mar 17, 2024
1 parent 5c48d11 commit 7dbb2a9
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/utils/fetch.ts
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ export async function fetchApi<T extends object>(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') {

0 comments on commit 7dbb2a9

Please sign in to comment.