map layer management
This commit is contained in:
22
api/http.ts
Normal file
22
api/http.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
export class ApiError extends Error {
|
||||
status: number;
|
||||
body: string;
|
||||
|
||||
constructor(message: string, status: number, body: string) {
|
||||
super(message);
|
||||
this.name = "ApiError";
|
||||
this.status = status;
|
||||
this.body = body;
|
||||
}
|
||||
}
|
||||
|
||||
export async function requestJson<T>(input: RequestInfo | URL, init?: RequestInit): Promise<T> {
|
||||
const res = await fetch(input, init);
|
||||
|
||||
if (!res.ok) {
|
||||
const text = await res.text();
|
||||
throw new ApiError(`Request failed with status ${res.status}`, res.status, text);
|
||||
}
|
||||
|
||||
return (await res.json()) as T;
|
||||
}
|
||||
Reference in New Issue
Block a user