From df1b128cbbe2a2d29df041f9eeb6931bce845eed Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 29 Oct 2023 07:55:47 +0100 Subject: [PATCH] Nicely format error toasts Signed-off-by: DL6ER --- scripts/pi-hole/js/utils.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/scripts/pi-hole/js/utils.js b/scripts/pi-hole/js/utils.js index b3c87040..15de336b 100644 --- a/scripts/pi-hole/js/utils.js +++ b/scripts/pi-hole/js/utils.js @@ -111,6 +111,20 @@ function showAlert(type, icon, title, message) { options.title = " Error, something went wrong!
"; 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 = " " + data.error.message + "
"; + + if (data.error.hint !== null) options.message = data.error.hint; + } + } catch { + // Do nothing + } + break; default: // Case not handled, do nothing