24 lines
359 B
JavaScript
24 lines
359 B
JavaScript
|
|
const API="/resman/api";
|
|
|
|
async function api(url, options={}){
|
|
|
|
const res = await fetch(url, options);
|
|
|
|
if(!res.ok){
|
|
|
|
let msg="API error";
|
|
|
|
try{
|
|
const err=await res.json();
|
|
msg=err.error || msg;
|
|
}catch(e){}
|
|
|
|
alert("Fehler: "+msg);
|
|
throw new Error(msg);
|
|
}
|
|
|
|
return res.json();
|
|
}
|
|
|