sync
CI / backend-and-migrations (push) Canceled after 0s
CI / astro-build (push) Canceled after 0s
CI / compose-e2e (push) Canceled after 0s

This commit is contained in:
ik
2026-09-08 09:31:41 +07:00
parent 8b2d7e2e1c
commit ddb6909c4d
21 changed files with 255 additions and 58 deletions
+5 -1
View File
@@ -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>;
}