export class ApiError extends Error { constructor( public status: number, message: string, ) { super(message); } } export async function apiFetch(url: string, options?: RequestInit): Promise { const res = await fetch(url, options); const data = await res.json(); if (!res.ok) { throw new ApiError( res.status, typeof data.error === "string" ? data.error : "Something went wrong.", ); } return data as T; }