tududi/frontend/utils/fetcher.ts
Antonis Anastasiadis 220bc92b4a
Lint frontend (#131)
* Add lint-fix npm target

* Sync eslint+plugins with backend

* Add prettier

* Ignore no-explicit-any lint rule for now

* Silence eslint react warning

* Format frontend via prettier

* Lint frontend.

---------

Co-authored-by: antanst <>
2025-07-09 12:23:55 +03:00

20 lines
541 B
TypeScript

export const fetcher = async (url: string) => {
const response = await fetch(url, {
credentials: 'include',
headers: {
Accept: 'application/json',
},
});
if (!response.ok) {
const errorData = await response.json();
const error = new Error(
errorData.error || 'An error occurred while fetching the data.'
);
(error as any).info = errorData;
(error as any).status = response.status;
throw error;
}
return response.json();
};