13 lines
393 B
TypeScript
13 lines
393 B
TypeScript
/**
|
|
* Client-side fetch function for API requests.
|
|
*/
|
|
export async function fetchData(url: string, options: RequestInit = {}): Promise<any> {
|
|
try {
|
|
const res = await fetch(url, options);
|
|
if (!res.ok) throw new Error(`Request failed: ${res.statusText}`);
|
|
return res.json();
|
|
} catch (error) {
|
|
console.error(`Fetch error at ${url}:`, error);
|
|
throw error;
|
|
}
|
|
} |