Handling exceptions
If an exception is encountered inside a callback passed to a Bacon helper function, then it's not caught automatically; rather, we have to use a try…catch
statement to handle it. A common practice is to return a Bacon.Error
instance after catching an exception so that we can handle it just like an error.
Here is an example of how to handle exceptions. In the index.js
file, find the following code:
var response = url.flatMap(function(value){ return Bacon.retry({ source: function(){ return Bacon.fromPromise($.ajax({url:value})); }, retries: 5, isRetryable: function (error) { return error.status !== 404; }, delay: function(context) { return 2000; } }) }).toProperty();
Replace it with this:
var response = url.flatMap(function(value){ try { return Bacon.retry({ source: function(){ return Bacon.fromPromise($.ajax({url:value})); }, retries: 5, isRetryable: function (error) { return error.status !== 404; }, delay: function(context...