From 91076a50ad2181d310cdda68f8f5fe60b2dd95ac Mon Sep 17 00:00:00 2001 From: "D. Berge" Date: Sat, 9 Sep 2023 17:00:32 +0200 Subject: [PATCH] Show API error messages if available --- lib/www/client/source/src/store/modules/api/actions.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/www/client/source/src/store/modules/api/actions.js b/lib/www/client/source/src/store/modules/api/actions.js index 80233a4..6be81d9 100644 --- a/lib/www/client/source/src/store/modules/api/actions.js +++ b/lib/www/client/source/src/store/modules/api/actions.js @@ -35,7 +35,14 @@ async function api ({state, commit, dispatch}, [resource, init = {}, cb]) { throw err; } } 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) { if (err && err.name == "AbortError") return;