diff --git a/assets/app.js b/assets/app.js index e970f045..7b4b1baf 100755 --- a/assets/app.js +++ b/assets/app.js @@ -1,9 +1,2 @@ import './bootstrap.js'; -/* - * Welcome to your app's main JavaScript file! - * - * We recommend including the built version of this JavaScript file - * (and its CSS file) in your base layout (base.html.twig). - */ - -// any CSS you import will output into a single css file (app.css in this case) \ No newline at end of file +import './error_handling' diff --git a/assets/error_handling.js b/assets/error_handling.js new file mode 100755 index 00000000..59adc106 --- /dev/null +++ b/assets/error_handling.js @@ -0,0 +1,35 @@ +window.addEventListener("unhandledrejection", (event) => { + const requestInfo = event.target.requestInformation; + const timestamp = new Date(); + + // Hide the form + document.getElementById("form").classList.add('hidden'); + + // Show the error report + document.getElementById("errorData").classList.remove('hidden'); + let errorFields = document.querySelectorAll('[data-content-for]'); + let written = false; + errorFields.forEach((element) => { + fieldName = element.dataset.contentFor; + written = false; + // 1. The timestamp is filled with the current time + if (fieldName === 'timestamp') { + element.innerHTML = timestamp.toISOString(); + written = true; + } + // Other fields are displayed from the requestInformation that is present in the event + if (requestInfo.hasOwnProperty(fieldName)) { + element.innerHTML = requestInfo[fieldName]; + written = true; + } + // Show the error message from the uncaught exception + if (fieldName === 'errorMessage' && requestInfo['errorMessage'] === undefined ) { + element.innerHTML = event.reason.message; + written = true; + } + // If no sensible data was available to write error field, remove the tr + if (!written) { + element.parentElement.remove(); + } + }); +}); diff --git a/templates/Exception/error.html.twig b/templates/Exception/error.html.twig index 386e630e..11eb8928 100644 --- a/templates/Exception/error.html.twig +++ b/templates/Exception/error.html.twig @@ -6,40 +6,17 @@ {% block body %}
{{ description }}
-{{ 'stepup.error.timestamp'|trans }} | -{{ timestamp }} | -
---|---|
{{ 'stepup.error.hostname'|trans }} | -{{ hostname }} | -
{{ 'stepup.error.request_id'|trans }} | -{{ request_id }} | -
{{ 'stepup.error.error_code'|trans }} | -{{ errorMessage }} | -
{{ 'stepup.error.sari'|trans }} | -{{ sari }} | -
{{ 'stepup.error.user_agent'|trans }} | -{{ user_agent }} | -
{{ 'stepup.error.ip_address'|trans }} | -{{ ip_address }} | -
{{ 'stepup.error.support_page.text'|trans({'%support_url%': global_view_parameters.supportUrl })|raw }}
diff --git a/templates/default/authentication.html.twig b/templates/default/authentication.html.twig index 6b23e664..7c62334f 100644 --- a/templates/default/authentication.html.twig +++ b/templates/default/authentication.html.twig @@ -3,8 +3,8 @@ {% block body %}{{ 'stepup.error.timestamp'|trans }} | +{{ timestamp }} | +
---|---|
{{ 'stepup.error.hostname'|trans }} | +{{ hostname }} | +
{{ 'stepup.error.request_id'|trans }} | +{{ requestId }} | +
{{ 'stepup.error.error_code'|trans }} | +{{ errorMessage }} | +
{{ 'stepup.error.sari'|trans }} | +{{ sari }} | +
{{ 'stepup.error.user_agent'|trans }} | +{{ userAgent }} | +
{{ 'stepup.error.ip_address'|trans }} | +{{ ipAddress }} | +