23 lines
321 B
JavaScript
23 lines
321 B
JavaScript
const API = "/resman/api"
|
|
|
|
async function api(url, options = {}) {
|
|
const res = await fetch(url, options)
|
|
|
|
let data
|
|
|
|
try {
|
|
data = await res.json()
|
|
} catch {
|
|
data = {}
|
|
}
|
|
|
|
if (!res.ok) {
|
|
const msg = data.error || "Unbekannter Fehler"
|
|
|
|
showError(msg)
|
|
|
|
throw new Error(msg)
|
|
}
|
|
|
|
return data
|
|
} |