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