Skip to content
Snippets Groups Projects
Commit 357e14ae authored by Sascha Herzinger's avatar Sascha Herzinger Committed by Piotr Gawron
Browse files

new handling of error (not every error should be reported)

parent c2677363
No related branches found
No related tags found
2 merge requests!630WIP: Resolve "The privileges of a new user are not saved in some cases",!589Feature error reporting
......@@ -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;
};
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment