blob: b31461599d8bb7acc54deeb79980ad18d8ef64c5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
async function handle_fetch(promise) {
const result = await promise;
const json = await result.json();
if (!result.ok) {
throw json;
}
return json;
}
export function get(url) {
return handle_fetch(fetch(url));
}
export async function post(url, body) {
return handle_fetch(fetch(url, {
method: 'POST',
body: JSON.stringify(body),
}));
}
|