import * as bootbox from "bootbox";
/**
* If this class is imported the user is shown an error dialog if he calls an page via Turbo and an error is responded.
* @type {ErrorHandlerHelper}
*/
class ErrorHandlerHelper {
constructor() {
console.log('Error Handler registered');
const content = document.getElementById('content');
content.addEventListener('turbo:before-fetch-response', (event) => this.handleError(event));
$(document).ajaxError(this.handleJqueryErrror.bind(this));
}
_showAlert(statusText, statusCode, location, responseHTML)
{
//Create error text
const title = statusText + ' (Status ' + statusCode + ')';
let trimString = function (string, length) {
return string.length > length ?
string.substring(0, length) + '...' :
string;
};
const short_location = trimString(location, 50);
const alert = bootbox.alert(
{
size: 'large',
message: function() {
let url = location;
let msg = `Error calling ${short_location}.
`;
msg += 'Try to reload the page or contact the administrator if this error persists.';
msg += '
' + 'View details' + "";
msg += "
' + err + ''); }); } } } export default new ErrorHandlerHelper();