Nicely format error toasts

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER
2023-10-29 07:55:47 +01:00
parent a8a5d39487
commit df1b128cbb

View File

@@ -111,6 +111,20 @@ function showAlert(type, icon, title, message) {
options.title = "&nbsp;<strong>Error, something went wrong!</strong><br>";
settings.delay *= 2;
// If the message is an API object, nicely format the error message
// Try to parse message as JSON
try {
var data = JSON.parse(message);
console.log(data); // eslint-disable-line no-console
if (data.error !== undefined) {
options.title = "&nbsp;<strong>" + data.error.message + "</strong><br>";
if (data.error.hint !== null) options.message = data.error.hint;
}
} catch {
// Do nothing
}
break;
default:
// Case not handled, do nothing