I have a web page where there are a bunch of items that the user can click on. clicking on any item, depending on it's type, will send an ajax request to the server and then display more items. If the request results in an error, I want to display it and then allow the user to continue clicking or interacting with the page as before.
My code looks like this
$scope.$createObservableFunction("clickHandler")
.flatMapLatest(function (args) {
//send the ajax request to the server
})
.retry()
.subscribe(function (data) {
//handle getting the data from the server
})
where exactly can I handle the error case? I expect errors to happen, and I always want to re-subscribe to the source, but I want a chance to handle that error.
The trick is to turn your errors into data:
If your ajax method returns a
Promise
, usethen
chaining: