Global AJAX error handling

This commit is contained in:
Alex Tselegidis 2020-12-02 19:57:49 +02:00
parent a689d23f25
commit 2ccc236bc2
20 changed files with 58 additions and 113 deletions

View file

@ -52,8 +52,6 @@ window.BackendCalendarApi = window.BackendCalendarApi || {};
} }
}) })
.fail(function (jqXHR, textStatus, errorThrown) { .fail(function (jqXHR, textStatus, errorThrown) {
GeneralFunctions.ajaxFailureHandler(jqXHR, textStatus, errorThrown);
if (errorCallback) { if (errorCallback) {
errorCallback(); errorCallback();
} }
@ -82,8 +80,6 @@ window.BackendCalendarApi = window.BackendCalendarApi || {};
} }
}) })
.fail(function (jqXHR, textStatus, errorThrown) { .fail(function (jqXHR, textStatus, errorThrown) {
GeneralFunctions.ajaxFailureHandler(jqXHR, textStatus, errorThrown);
if (errorCallback) { if (errorCallback) {
errorCallback(); errorCallback();
} }
@ -117,8 +113,6 @@ window.BackendCalendarApi = window.BackendCalendarApi || {};
} }
}) })
.fail(function (jqXHR, textStatus, errorThrown) { .fail(function (jqXHR, textStatus, errorThrown) {
GeneralFunctions.ajaxFailureHandler(jqXHR, textStatus, errorThrown);
if (errorCallback) { if (errorCallback) {
errorCallback(); errorCallback();
} }
@ -141,8 +135,6 @@ window.BackendCalendarApi = window.BackendCalendarApi || {};
} }
}) })
.fail(function (jqXHR, textStatus, errorThrown) { .fail(function (jqXHR, textStatus, errorThrown) {
GeneralFunctions.ajaxFailureHandler(jqXHR, textStatus, errorThrown);
if (errorCallback) { if (errorCallback) {
errorCallback(); errorCallback();
} }

View file

@ -224,8 +224,7 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
// Refresh calendar event items. // Refresh calendar event items.
$('#select-filter-item').trigger('change'); $('#select-filter-item').trigger('change');
}) });
.fail(GeneralFunctions.ajaxFailureHandler);
} }
} }
]; ];
@ -255,8 +254,7 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
// Refresh calendar event items. // Refresh calendar event items.
$('#select-filter-item').trigger('change'); $('#select-filter-item').trigger('change');
}) });
.fail(GeneralFunctions.ajaxFailureHandler);
} }
}); });
@ -728,8 +726,7 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
.done(function () { .done(function () {
$('#notification').hide('blind'); $('#notification').hide('blind');
revertFunc(); revertFunc();
}) });
.fail(GeneralFunctions.ajaxFailureHandler);
}; };
Backend.displayNotification(EALang.appointment_updated, [ Backend.displayNotification(EALang.appointment_updated, [
@ -777,8 +774,7 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
.done(function () { .done(function () {
$('#notification').hide('blind'); $('#notification').hide('blind');
revertFunc(); revertFunc();
}) });
.fail(GeneralFunctions.ajaxFailureHandler);
}; };
Backend.displayNotification(EALang.unavailable_updated, [ Backend.displayNotification(EALang.unavailable_updated, [
@ -898,8 +894,7 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
.done(function () { .done(function () {
$('#notification').hide('blind'); $('#notification').hide('blind');
revertFunc(); revertFunc();
}) });
.fail(GeneralFunctions.ajaxFailureHandler);
}; };
Backend.displayNotification(EALang.appointment_updated, [ Backend.displayNotification(EALang.appointment_updated, [
@ -948,8 +943,7 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
.done(function () { .done(function () {
$('#notification').hide('blind'); $('#notification').hide('blind');
revertFunc(); revertFunc();
}) });
.fail(GeneralFunctions.ajaxFailureHandler);
}; };
Backend.displayNotification(EALang.unavailable_updated, [ Backend.displayNotification(EALang.unavailable_updated, [
@ -1366,7 +1360,6 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
} }
} }
}) })
.fail(GeneralFunctions.ajaxFailureHandler)
.always(function () { .always(function () {
$('#loading').css('visibility', '') $('#loading').css('visibility', '')
}); });

View file

@ -77,8 +77,7 @@ window.BackendCalendarGoogleSync = window.BackendCalendarGoogleSync || {};
}); });
$('#select-google-calendar').modal('show'); $('#select-google-calendar').modal('show');
}) });
.fail(GeneralFunctions.ajaxFailureHandler);
} }
} }
} catch (Error) { } catch (Error) {
@ -125,8 +124,7 @@ window.BackendCalendarGoogleSync = window.BackendCalendarGoogleSync || {};
.done(function () { .done(function () {
Backend.displayNotification(EALang.google_calendar_selected); Backend.displayNotification(EALang.google_calendar_selected);
$('#select-google-calendar').modal('hide'); $('#select-google-calendar').modal('hide');
}) });
.fail(GeneralFunctions.ajaxFailureHandler);
}); });
/** /**
@ -169,8 +167,7 @@ window.BackendCalendarGoogleSync = window.BackendCalendarGoogleSync || {};
provider_id: providerId provider_id: providerId
}; };
$.post(url, data) $.post(url, data);
.fail(GeneralFunctions.ajaxFailureHandler);
} }

View file

@ -117,9 +117,7 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
// setCalendarViewSize(); // setCalendarViewSize();
Backend.placeFooterToBottom(); Backend.placeFooterToBottom();
});
})
.fail(GeneralFunctions.ajaxFailureHandler);
}); });
/** /**
@ -266,8 +264,7 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
// Refresh calendar event items. // Refresh calendar event items.
$('#select-filter-item').trigger('change'); $('#select-filter-item').trigger('change');
}) });
.fail(GeneralFunctions.ajaxFailureHandler);
} else if (lastFocusedEventData.data.is_unavailable === '0') { } else if (lastFocusedEventData.data.is_unavailable === '0') {
var buttons = [ var buttons = [
{ {
@ -293,8 +290,7 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
// Refresh calendar event items. // Refresh calendar event items.
$('#select-filter-item').trigger('change'); $('#select-filter-item').trigger('change');
}) });
.fail(GeneralFunctions.ajaxFailureHandler);
} }
} }
]; ];
@ -323,8 +319,7 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
// Refresh calendar event items. // Refresh calendar event items.
$('#select-filter-item').trigger('change'); $('#select-filter-item').trigger('change');
}) });
.fail(GeneralFunctions.ajaxFailureHandler);
} }
}); });
} }
@ -540,9 +535,7 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
$providerColumn.find('.calendar-wrapper') $providerColumn.find('.calendar-wrapper')
.fullCalendar('changeView', providerView[providerId] || 'agendaDay'); .fullCalendar('changeView', providerView[providerId] || 'agendaDay');
}); });
});
})
.fail(GeneralFunctions.ajaxFailureHandler);
} }
/** /**
@ -1466,8 +1459,7 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
.done(function () { .done(function () {
$('#notification').hide('blind'); $('#notification').hide('blind');
revertFunc(); revertFunc();
}) });
.fail(GeneralFunctions.ajaxFailureHandler);
}; };
Backend.displayNotification(EALang.appointment_updated, [ Backend.displayNotification(EALang.appointment_updated, [
@ -1515,8 +1507,7 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
.done(function () { .done(function () {
$('#notification').hide('blind'); $('#notification').hide('blind');
revertFunc(); revertFunc();
}) });
.fail(GeneralFunctions.ajaxFailureHandler);
}; };
Backend.displayNotification(EALang.unavailable_updated, [ Backend.displayNotification(EALang.unavailable_updated, [
@ -1605,8 +1596,7 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
.done(function () { .done(function () {
$('#notification').hide('blind'); $('#notification').hide('blind');
revertFunc(); revertFunc();
}) });
.fail(GeneralFunctions.ajaxFailureHandler);
}; };
Backend.displayNotification(EALang.appointment_updated, [ Backend.displayNotification(EALang.appointment_updated, [
@ -1656,8 +1646,7 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
.done(function () { .done(function () {
$('#notification').hide('blind'); $('#notification').hide('blind');
revertFunc(); revertFunc();
}) });
.fail(GeneralFunctions.ajaxFailureHandler);
}; };
Backend.displayNotification(EALang.unavailable_updated, [ Backend.displayNotification(EALang.unavailable_updated, [

View file

@ -207,8 +207,7 @@
if (selectId) { if (selectId) {
this.select(selectId, display); this.select(selectId, display);
} }
}.bind(this)) }.bind(this));
.fail(GeneralFunctions.ajaxFailureHandler);
}; };
/** /**
@ -231,8 +230,7 @@
$('#filter-categories .key').val(''); $('#filter-categories .key').val('');
this.filter('', response.id, true); this.filter('', response.id, true);
BackendServices.updateAvailableCategories(); BackendServices.updateAvailableCategories();
}.bind(this)) }.bind(this));
.fail(GeneralFunctions.ajaxFailureHandler);
}; };
/** /**
@ -255,8 +253,7 @@
this.resetForm(); this.resetForm();
this.filter($('#filter-categories .key').val()); this.filter($('#filter-categories .key').val());
BackendServices.updateAvailableCategories(); BackendServices.updateAvailableCategories();
}.bind(this)) }.bind(this));
.fail(GeneralFunctions.ajaxFailureHandler);
}; };
/** /**

View file

@ -185,8 +185,7 @@
this.resetForm(); this.resetForm();
$('#filter-customers .key').val(''); $('#filter-customers .key').val('');
this.filter('', response.id, true); this.filter('', response.id, true);
}.bind(this)) }.bind(this));
.fail(GeneralFunctions.ajaxFailureHandler);
}; };
/** /**
@ -207,8 +206,7 @@
Backend.displayNotification(EALang.customer_deleted); Backend.displayNotification(EALang.customer_deleted);
this.resetForm(); this.resetForm();
this.filter($('#filter-customers .key').val()); this.filter($('#filter-customers .key').val());
}.bind(this)) }.bind(this));
.fail(GeneralFunctions.ajaxFailureHandler);
}; };
/** /**
@ -412,8 +410,7 @@
this.select(selectId, display); this.select(selectId, display);
} }
}.bind(this)) }.bind(this));
.fail(GeneralFunctions.ajaxFailureHandler);
}; };
/** /**

View file

@ -110,7 +110,6 @@ window.BackendServices = window.BackendServices || {};
}); });
$select.append(new Option('- ' + EALang.no_category + ' -', null)).val('null'); $select.append(new Option('- ' + EALang.no_category + ' -', null)).val('null');
}) });
.fail(GeneralFunctions.ajaxFailureHandler);
}; };
})(window.BackendServices); })(window.BackendServices);

View file

@ -208,8 +208,7 @@
this.resetForm(); this.resetForm();
$('#filter-services .key').val(''); $('#filter-services .key').val('');
this.filter('', response.id, true); this.filter('', response.id, true);
}.bind(this)) }.bind(this));
.fail(GeneralFunctions.ajaxFailureHandler);
}; };
/** /**
@ -231,8 +230,7 @@
this.resetForm(); this.resetForm();
this.filter($('#filter-services .key').val()); this.filter($('#filter-services .key').val());
}.bind(this)) }.bind(this));
.fail(GeneralFunctions.ajaxFailureHandler);
}; };
/** /**
@ -365,8 +363,7 @@
if (selectId) { if (selectId) {
this.select(selectId, display); this.select(selectId, display);
} }
}.bind(this)) }.bind(this));
.fail(GeneralFunctions.ajaxFailureHandler);
}; };
/** /**

View file

@ -218,8 +218,7 @@ window.BackendSettings = window.BackendSettings || {};
$input.closest('.form-group').removeClass('has-error'); $input.closest('.form-group').removeClass('has-error');
$input.attr('already-exists', 'false'); $input.attr('already-exists', 'false');
} }
}) });
.fail(GeneralFunctions.ajaxFailureHandler);
}); });
/** /**
@ -247,7 +246,6 @@ window.BackendSettings = window.BackendSettings || {};
.done(function () { .done(function () {
Backend.displayNotification(EALang.working_plans_got_updated); Backend.displayNotification(EALang.working_plans_got_updated);
}) })
.fail(GeneralFunctions.ajaxFailureHandler)
.always(function() { .always(function() {
$('#message-box').dialog('close'); $('#message-box').dialog('close');
}); });

View file

@ -60,8 +60,7 @@
var workingPlan = BackendSettings.wp.get(); var workingPlan = BackendSettings.wp.get();
BackendSettings.wp.setup(workingPlan); BackendSettings.wp.setup(workingPlan);
BackendSettings.wp.timepickers(false); BackendSettings.wp.timepickers(false);
}) });
.fail(GeneralFunctions.ajaxFailureHandler);
}; };
/** /**

View file

@ -79,8 +79,7 @@
// Update footer greetings. // Update footer greetings.
$('#footer-user-display-name').text('Hello, ' + $('#first-name').val() + ' ' + $('#last-name').val() + '!'); $('#footer-user-display-name').text('Hello, ' + $('#first-name').val() + ' ' + $('#last-name').val() + '!');
}) });
.fail(GeneralFunctions.ajaxFailureHandler);
}; };
/** /**

View file

@ -181,8 +181,7 @@ window.BackendUsers = window.BackendUsers || {};
}) })
.appendTo('#secretary-providers'); .appendTo('#secretary-providers');
}); });
}) });
.fail(GeneralFunctions.ajaxFailureHandler);
} }
helper.resetForm(); helper.resetForm();
@ -233,8 +232,7 @@ window.BackendUsers = window.BackendUsers || {};
$input.parents().eq(3).find('.form-message').hide(); $input.parents().eq(3).find('.form-message').hide();
} }
} }
}) });
.fail(GeneralFunctions.ajaxFailureHandler);
}); });
} }

View file

@ -200,8 +200,7 @@
this.resetForm(); this.resetForm();
$('#filter-admins .key').val(''); $('#filter-admins .key').val('');
this.filter('', response.id, true); this.filter('', response.id, true);
}.bind(this)) }.bind(this));
.fail(GeneralFunctions.ajaxFailureHandler);
}; };
/** /**
@ -222,8 +221,7 @@
Backend.displayNotification(EALang.admin_deleted); Backend.displayNotification(EALang.admin_deleted);
this.resetForm(); this.resetForm();
this.filter($('#filter-admins .key').val()); this.filter($('#filter-admins .key').val());
}.bind(this)) }.bind(this));
.fail(GeneralFunctions.ajaxFailureHandler);
}; };
/** /**
@ -379,8 +377,7 @@
if (selectId) { if (selectId) {
this.select(selectId, display); this.select(selectId, display);
} }
}.bind(this)) }.bind(this));
.fail(GeneralFunctions.ajaxFailureHandler);
}; };
/** /**

View file

@ -236,8 +236,7 @@
this.resetForm(); this.resetForm();
$('#filter-providers .key').val(''); $('#filter-providers .key').val('');
this.filter('', response.id, true); this.filter('', response.id, true);
}.bind(this)) }.bind(this));
.fail(GeneralFunctions.ajaxFailureHandler);
}; };
/** /**
@ -257,8 +256,7 @@
Backend.displayNotification(EALang.provider_deleted); Backend.displayNotification(EALang.provider_deleted);
this.resetForm(); this.resetForm();
this.filter($('#filter-providers .key').val()); this.filter($('#filter-providers .key').val());
}.bind(this)) }.bind(this));
.fail(GeneralFunctions.ajaxFailureHandler);
}; };
/** /**
@ -484,8 +482,7 @@
if (selectId) { if (selectId) {
this.select(selectId, display); this.select(selectId, display);
} }
}.bind(this)) }.bind(this));
.fail(GeneralFunctions.ajaxFailureHandler);
}; };
/** /**

View file

@ -214,8 +214,7 @@
this.resetForm(); this.resetForm();
$('#filter-secretaries .key').val(''); $('#filter-secretaries .key').val('');
this.filter('', response.id, true); this.filter('', response.id, true);
}.bind(this)) }.bind(this));
.fail(GeneralFunctions.ajaxFailureHandler);
}; };
/** /**
@ -236,8 +235,7 @@
Backend.displayNotification(EALang.secretary_deleted); Backend.displayNotification(EALang.secretary_deleted);
this.resetForm(); this.resetForm();
this.filter($('#filter-secretaries .key').val()); this.filter($('#filter-secretaries .key').val());
}.bind(this)) }.bind(this));
.fail(GeneralFunctions.ajaxFailureHandler);
}; };
/** /**
@ -406,8 +404,7 @@
if (selectId) { if (selectId) {
this.select(selectId, display); this.select(selectId, display);
} }
}.bind(this)) }.bind(this));
.fail(GeneralFunctions.ajaxFailureHandler);
}; };
/** /**

View file

@ -37,8 +37,7 @@ $(function () {
$alert.text('The operation failed! Please enter a valid username ' $alert.text('The operation failed! Please enter a valid username '
+ 'and email address in order to get a new password.'); + 'and email address in order to get a new password.');
} }
}) });
.fail(GeneralFunctions.ajaxFailureHandler);
} }

View file

@ -126,8 +126,7 @@ window.FrontendBookApi = window.FrontendBookApi || {};
} else { } else {
$('#available-hours').text(EALang.no_available_hours); $('#available-hours').text(EALang.no_available_hours);
} }
}) });
.fail(GeneralFunctions.ajaxFailureHandler);
}; };
/** /**
@ -206,7 +205,6 @@ window.FrontendBookApi = window.FrontendBookApi || {};
}) })
.fail(function (jqxhr, textStatus, errorThrown) { .fail(function (jqxhr, textStatus, errorThrown) {
$('.captcha-title small').trigger('click'); $('.captcha-title small').trigger('click');
GeneralFunctions.ajaxFailureHandler(jqxhr, textStatus, errorThrown);
}) })
.always(function () { .always(function () {
$layer.remove(); $layer.remove();
@ -256,8 +254,7 @@ window.FrontendBookApi = window.FrontendBookApi || {};
unavailableDatesBackup = response; unavailableDatesBackup = response;
selectedDateStringBackup = selectedDateString; selectedDateStringBackup = selectedDateString;
applyUnavailableDates(response, selectedDateString, true); applyUnavailableDates(response, selectedDateString, true);
}) });
.fail(GeneralFunctions.ajaxFailureHandler);
}; };
exports.applyPreviousUnavailableDates = function () { exports.applyPreviousUnavailableDates = function () {
@ -313,7 +310,7 @@ window.FrontendBookApi = window.FrontendBookApi || {};
consent: consent consent: consent
}; };
$.post(url, data).fail(GeneralFunctions.ajaxFailureHandler); $.post(url, data);
}; };
/** /**
@ -331,9 +328,8 @@ window.FrontendBookApi = window.FrontendBookApi || {};
$.post(url, data) $.post(url, data)
.done(function () { .done(function () {
location.href = GlobalVariables.baseUrl; window.location.href = GlobalVariables.baseUrl;
}) });
.fail(GeneralFunctions.ajaxFailureHandler);
}; };
})(window.FrontendBookApi); })(window.FrontendBookApi);

View file

@ -22,6 +22,13 @@ window.GeneralFunctions = window.GeneralFunctions || {};
'use strict'; 'use strict';
/**
* Register global error handler.
*/
$(document).ajaxError(function (event, jqxhr, settings, thrownError) {
GeneralFunctions.ajaxFailureHandler(jqxhr, settings, thrownError);
});
/** /**
* This functions displays a message box in the admin array. It is useful when user * This functions displays a message box in the admin array. It is useful when user
* decisions or verifications are needed. * decisions or verifications are needed.
@ -288,8 +295,7 @@ window.GeneralFunctions = window.GeneralFunctions || {};
$.post(url, data) $.post(url, data)
.done(function () { .done(function () {
document.location.reload(true); document.location.reload(true);
}) });
.fail(GeneralFunctions.ajaxFailureHandler);
}); });
$(document).on('click', function() { $(document).on('click', function() {

View file

@ -56,8 +56,7 @@ $(function () {
setTimeout(function () { setTimeout(function () {
window.location.href = GlobalVariables.baseUrl + '/index.php/backend'; window.location.href = GlobalVariables.baseUrl + '/index.php/backend';
}, 1000); }, 1000);
}) });
.fail(GeneralFunctions.ajaxFailureHandler);
}); });
/** /**

View file

@ -34,8 +34,7 @@ $(function () {
.removeClass('d-none alert-danger alert-success') .removeClass('d-none alert-danger alert-success')
.addClass('alert-danger'); .addClass('alert-danger');
} }
}) });
.fail(GeneralFunctions.ajaxFailureHandler);
} }
$loginForm.on('submit', onLoginFormSubmit); $loginForm.on('submit', onLoginFormSubmit);