I want to chain my promises depending upon if the previous call was resolved or rejected. I am making a call to server in all promises. So, I am writing it like-
apiServices.patientsSearch(id)
.then(function(data){
return callback(null,data);
},function(err){
return apiServices.studiesSearch(id);
}).then(function(data){
return callback(null,data);
},function(){
return apiServices.seriesSearch(id);
}).then(function(data){
return callback(null,data);
})
.catch(function(err){
return callback(false,err);
});
As every then returns a promise object, problem is that catch is always being called if any promise except the last one calls resolve. One way I am thinking is to check if err is empty and ignore it. Is it the right way to do it ?
I am using request module, if I set forever: true, I start getting-
{ [Error: socket hang up] code: 'ECONNRESET' }
With forever false, it works. Why my socket is still busy even after the request has ended ? As the next request will go only when reject is called, so socket should be free by that time.