sync
This commit is contained in:
@@ -20,8 +20,12 @@ export { activityLevel, ago, kg, plural } from "./presentation";
|
||||
|
||||
const base = process.env.API_INTERNAL_URL || import.meta.env.API_INTERNAL_URL || "http://localhost:8000";
|
||||
|
||||
export class ApiError extends Error {
|
||||
constructor(public status: number) { super(`API ${status}`); }
|
||||
}
|
||||
|
||||
export async function api<T>(path: string): Promise<T> {
|
||||
const response = await fetch(`${base}${path}`);
|
||||
if (!response.ok) throw new Error(`API ${response.status}`);
|
||||
if (!response.ok) throw new ApiError(response.status);
|
||||
return response.json() as Promise<T>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user