How to handle server errors in backbone.js?

In Backbonejs , how can I handle any server errors when using fetch() ?

+4
source share
1 answer

If you are technically asking how to respond to an error, then:

There are several ways to do this.

The simplest is that various transaction functions support success and error callbacks:

 myModel.save({property: "value", property2: "value2"},{success: function(model,response){...}, error: function(model,response){...}}); 

or, in coffeescript:

 myModel.save property: "value" property2: "value2 , success: (model, response) -> ... error: (model, response) -> ... 

Another way is that since Backbone uses jquery.ajax behind the scenes, use the jquery.ajaxError handler.

If you are looking for a strategy on how, from a product perspective, to handle errors, I think it depends on what you do.

+5
source

Source: https://habr.com/ru/post/1384742/


All Articles