Exosphere is a set of small, modular, self-hostable community tools built on the AT Protocol.
app.exosphere.site
1export class ApiError extends Error {
2 constructor(
3 public status: number,
4 message: string,
5 ) {
6 super(message);
7 }
8}
9
10export async function apiFetch<T>(url: string, options?: RequestInit): Promise<T> {
11 const res = await fetch(url, options);
12 const data = await res.json();
13 if (!res.ok) {
14 throw new ApiError(
15 res.status,
16 typeof data.error === "string" ? data.error : "Something went wrong.",
17 );
18 }
19 return data as T;
20}