Show API error messages if available

This commit is contained in:
D. Berge
2023-09-09 17:00:32 +02:00
parent e624dcdde0
commit 91076a50ad

View File

@@ -35,7 +35,14 @@ async function api ({state, commit, dispatch}, [resource, init = {}, cb]) {
throw err; throw err;
} }
} else { } else {
await dispatch('showSnack', [res.statusText, "warning"]); let message = res.statusText;
if (res.headers.get("Content-Type").match(/^application\/json/i)) {
const body = await res.json();
if (body.message) {
message = body.message;
}
}
await dispatch('showSnack', [message, "warning"]);
} }
} catch (err) { } catch (err) {
if (err && err.name == "AbortError") return; if (err && err.name == "AbortError") return;