vor subdomain UX anpassung
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
const API = "/resman/api"
|
||||
|
||||
async function api(url, options = {}) {
|
||||
async function api(url, options = {}, config = {}) {
|
||||
const showToast = config.showError !== false
|
||||
const res = await fetch(url, options)
|
||||
|
||||
let data
|
||||
@@ -14,10 +15,35 @@ async function api(url, options = {}) {
|
||||
if (!res.ok) {
|
||||
const msg = data.error || "Unbekannter Fehler"
|
||||
|
||||
showError(msg)
|
||||
if (showToast) {
|
||||
showError(msg)
|
||||
}
|
||||
|
||||
throw new Error(msg)
|
||||
const error = new Error(msg)
|
||||
error.status = res.status
|
||||
error.data = data
|
||||
|
||||
throw error
|
||||
}
|
||||
|
||||
return data
|
||||
}
|
||||
}
|
||||
|
||||
window.runAction = async function(action, onSuccess) {
|
||||
try {
|
||||
await action()
|
||||
|
||||
if (onSuccess) {
|
||||
await onSuccess()
|
||||
}
|
||||
|
||||
return true
|
||||
} catch (error) {
|
||||
if (error && error.silent) {
|
||||
return false
|
||||
}
|
||||
|
||||
console.error(error)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user