Skip to content

Commit

Permalink
Adding throw error statement on data-fetch failing. (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
yelodevopsi authored Oct 25, 2023
1 parent 41101d3 commit 3099455
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions frontend/src/data/fetchWithToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@ export async function fetchWithToken<T>(path: string): Promise<T | undefined> {
method: "GET",
headers: headers,
};

const completeUrl = `${apiBackendUrl}/${path}`;

try {
const response = await fetch(`${apiBackendUrl}/${path}`, options);
return (await response.json()) as T;
const response = await fetch(completeUrl, options);
const json = await response.json();
return json as T;
} catch (e) {
console.error(e);
throw new Error(`${options.method} ${completeUrl} failed`);
}
}

Expand Down

0 comments on commit 3099455

Please sign in to comment.