Is there way to bind one error handler for ajax requests that performs by backbone.js?
My situation: I can get 401 (Unauthorized) at any time, so I need to show logi
What I found is possibly the "most right way" in Backbone:
var GeneralErrorView = Backbone.View.extend({
events: {
'ajaxError': 'handleAjaxError'
},
handleAjaxError: function (event, request, settings, thrownError) {
//...handling goes here
}
});
this.view = GeneralErrorView({el: document});
You can put any error handling logic without extending Models or Collections. Make use of Backbone.Events inside handler and transmit messages to other error handlers or something like that.