I setup a Global AJAX error handling function, this way , but I don't see how to test it ? anyway in a jsFiddle
$(function () {
var statusErrorMap = {
'400' : "Server understood the request, but request content was invalid.",
'401' : "Unauthorized access.",
'403' : "Forbidden resource can't be accessed.",
'500' : "Internal server error.",
'503' : "Service unavailable."
};
//setup ajax error handling
$.ajaxSetup({
error: function (x, status, error) {
if (x.status in statusErrorMap) {
if (x.status == "503") {
alert("Sorry, your session has expired. Please login again to continue");
window.location.href ="/users/sign_in";
} else {
alert("("+ x.status +") error occurred: " + statusErrorMap[x.status.toString()]);
}
}
else {
alert("An error occurred: " + status + "nError: " + error);
}
}
});
});