diff --git a/frontend-js/src/main/js/GuiConnector.js b/frontend-js/src/main/js/GuiConnector.js index 7705a2399e7d7801db35008edadbf58ddb215211..1d1aa5ad8a8fcfcd0c7b5ec7c751004e4abdb74a 100644 --- a/frontend-js/src/main/js/GuiConnector.js +++ b/frontend-js/src/main/js/GuiConnector.js @@ -295,73 +295,71 @@ GuiConnector.prototype.alert = function (error, redirectIfSecurityError) { logger.error(error); var errorData = self.getErrorMessageForError(error); - var message = errorData.message; - var stacktrace = { - value: errorData.stack, - tooltip: 'The error stacktrace. The sequence of events that triggered this particular error.' - }; - self._errorDialog = document.createElement('div'); - self._errorDialog.innerHTML = '<span class="ui-icon ui-icon-info" style="float: right;" title="The error message. This might not be human readable. If this issue persists you should should contact your administrator."></span>' + - '<span>' + message + '</span>'; - self.gatherReportData().then(function (data) { - self._errorDialog.innerHTML += '<p class="report-dialog-warning">If you agree to submit the following information to the Minerva maintainers please uncheck all boxes that might contain sensitive data.</p>'; - self._errorDialogData = document.createElement('div'); - self._errorDialog.appendChild(self._errorDialogData); - self._errorDialogData.innerHTML += '<textarea id="report-comment" placeholder="Add comment..."></textarea>'; - Object.keys(data).forEach(function (key) { - self._errorDialogData.innerHTML += '<label>' + - data[key].value + - '<input class="report-check" type="checkbox" data-key="' + key + '" data-value="' + data[key].value + '"/>' + - '<span class="ui-icon ui-icon-info" title="' + data[key].tooltip + '"></span>' + - '</label>'; - }); - if (typeof stacktrace.value !== 'undefined') { + if (!errorData.showReport) { + + } else { + self._errorDialog = document.createElement('div'); + self._errorDialog.innerHTML = '<span class="ui-icon ui-icon-info" style="float: right;" title="The error message. This might not be human readable. If this issue persists you should should contact your administrator."></span>' + + '<span>' + errorData.message + '</span>'; + self.gatherReportData().then(function (data) { + self._errorDialog.innerHTML += '<p class="report-dialog-warning">If you agree to submit the following information to the Minerva maintainers please uncheck all boxes that might contain sensitive data.</p>'; + self._errorDialogData = document.createElement('div'); + self._errorDialog.appendChild(self._errorDialogData); + self._errorDialogData.innerHTML += '<textarea id="report-comment" placeholder="Add comment..."></textarea>'; + Object.keys(data).forEach(function (key) { + self._errorDialogData.innerHTML += '<label>' + + data[key].value + + '<input class="report-check" type="checkbox" data-key="' + key + '" data-value="' + data[key].value + '"/>' + + '<span class="ui-icon ui-icon-info" title="' + data[key].tooltip + '"></span>' + + '</label>'; + }); self._errorDialogData.innerHTML += '<div id="report-stacktrace">' + - '<h3>Stacktrace<span class="ui-icon ui-icon-info" title="' + stacktrace.tooltip + '"></span></h3>' + - '<div><p>' + stacktrace.value + '</p></div>' + + '<h3>Stacktrace' + + '<span class="ui-icon ui-icon-info" title="' + 'The error stacktrace. The sequence of events that triggered this particular error.' + '"></span>' + + '</h3>' + + '<div><p>' + errorData.stacktrace + '</p></div>' + '</div>'; $('#report-stacktrace') .accordion({active: false, collapsible: true}); - } - $('.report-check') - .checkboxradio() - .prop('checked', true) - .button('refresh'); - $(self._errorDialogData) - .controlgroup({direction: 'vertical'}); - $(self._errorDialog) - .tooltip(); - }); - document.body.appendChild(self._errorDialog); - $(self._errorDialog).dialog({ - classes: {'ui-dialog': 'report-dialog'}, - title: 'An error occurred!', - resizable: true, - height: 'auto', - width: '500px', - modal: true, - buttons: { - 'Submit': function () { - var report = { - stacktrace: stacktrace.value, - comment: $('#report-comment').val() - }; - $('.report-check').each(function () { - var check = $(this); - if (check.is(':checked')) { - report[check.attr('data-key')] = check.attr('data-value'); - } - }); - ServerConnector.submitErrorToMinervaNet(report); - $(this).dialog('destroy').remove(); - }, - 'Cancel': function () { - $(this).dialog('destroy').remove(); + $('.report-check') + .checkboxradio() + .prop('checked', true) + .button('refresh'); + $(self._errorDialogData) + .controlgroup({direction: 'vertical'}); + $(self._errorDialog) + .tooltip(); + }); + document.body.appendChild(self._errorDialog); + $(self._errorDialog).dialog({ + classes: {'ui-dialog': 'report-dialog'}, + title: 'An error occurred!', + resizable: true, + height: 'auto', + width: '500px', + modal: true, + buttons: { + 'Submit': function () { + var report = { + stacktrace: errorData.stacktrace, + comment: $('#report-comment').val() + }; + $('.report-check').each(function () { + var check = $(this); + if (check.is(':checked')) { + report[check.attr('data-key')] = check.attr('data-value'); + } + }); + ServerConnector.submitErrorToMinervaNet(report); + $(this).dialog('destroy').remove(); + }, + 'Cancel': function () { + $(this).dialog('destroy').remove(); + } } - } - }).dialog("open"); + }).dialog("open"); + } } - }; /** @@ -370,25 +368,21 @@ GuiConnector.prototype.alert = function (error, redirectIfSecurityError) { * @returns {Object} */ GuiConnector.prototype.getErrorMessageForError = function (error) { + var expectedError = typeof error === 'string' || error instanceof SecurityError; + var errorData = { + showReport: !expectedError, + message: typeof error === 'string' ? error : error.message, + stacktrace: error.stack + }; + if (error instanceof SecurityError) { if (ServerConnector.getSessionData().getLogin() === "anonymous") { - return { - message: error.message + "<p>Please <a href=\"login.xhtml?from=" + encodeURI(window.location.href) + "\">login</a> to access this resource</p>", - stack: error.stack - }; + errorData.message = "<p>Please <a href=\"login.xhtml?from=" + encodeURI(window.location.href) + "\">login</a> to access this resource</p>"; } else { - return { - message: error.message + "<p>Please <a href=\"login.xhtml?from=" + encodeURI(window.location.href) + "\">login</a> " + "as a different user or ask your administrator to change the permissions to access this resource.</p>", - stack: error.stack - }; + errorData.message += "<p>Please <a href=\"login.xhtml?from=" + encodeURI(window.location.href) + "\">login</a> " + "as a different user or ask your administrator to change the permissions to access this resource.</p>"; } - } else if (error instanceof ValidationError || error instanceof GuiMessageError || error instanceof Error) { - return { - message: error.message, - stack: error.stack - }; } - return { message: error }; + return errorData; }; /**