16 lines
453 B
TypeScript
Raw Normal View History

2024-05-12 06:00:04 +07:00
import { ClientResponse, hc } from "hono/client";
2024-05-12 19:30:45 +07:00
import type { AppRouter } from "@backend/routers";
2024-05-12 06:00:04 +07:00
const api = hc<AppRouter>("http://localhost:3000/");
export const parseJson = async <T>(res: ClientResponse<T>) => {
const json = await res.json();
if (!res.ok) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
throw new Error((json as any)?.message || "An error occured.");
}
return json as T;
};
export default api;