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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -79,8 +79,7 @@
// Update footer greetings.
$('#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');
});
})
.fail(GeneralFunctions.ajaxFailureHandler);
});
}
helper.resetForm();
@ -233,8 +232,7 @@ window.BackendUsers = window.BackendUsers || {};
$input.parents().eq(3).find('.form-message').hide();
}
}
})
.fail(GeneralFunctions.ajaxFailureHandler);
});
});
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -22,6 +22,13 @@ window.GeneralFunctions = window.GeneralFunctions || {};
'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
* decisions or verifications are needed.
@ -288,8 +295,7 @@ window.GeneralFunctions = window.GeneralFunctions || {};
$.post(url, data)
.done(function () {
document.location.reload(true);
})
.fail(GeneralFunctions.ajaxFailureHandler);
});
});
$(document).on('click', function() {

View file

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

View file

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