2023-11-17 23:52:51 +00:00
|
|
|
import { edenFetch } from "elysia/eden";
|
|
|
|
import { Api } from "../api/serveApi.ts";
|
2023-10-05 09:00:51 +00:00
|
|
|
|
2023-11-17 23:52:51 +00:00
|
|
|
export const fetchApi = edenFetch<Api>(`${location.origin}/api`);
|
2023-10-05 09:00:51 +00:00
|
|
|
|
2023-11-17 23:52:51 +00:00
|
|
|
export function handleResponse<D, E>(
|
|
|
|
response: { data: D; error: E },
|
|
|
|
): NonNullable<D> {
|
|
|
|
if (response.data) {
|
|
|
|
return response.data;
|
2023-10-05 09:00:51 +00:00
|
|
|
}
|
2023-11-17 23:52:51 +00:00
|
|
|
throw new Error(String(response.error));
|
2023-10-05 09:00:51 +00:00
|
|
|
}
|