我正在迭代地调用多个URL并为每个URL请求添加返回的promise到数组中。迭代之后,我使用$q.all()
来获取结果并将所有请求中的数据添加到单个数组中。
我的任务是将收集并存储在一个数组中,直到一个URL返回无数据。但是,根据$q.all
的实现,我读到如果一个承诺给出404错误,那么整批请求将被拒绝。 如何克服这个或者任何其他方式来实现我的任务?
var calculateMutationsInDepth = function(){
\t \t \t var depthRange=[0,1,2,3];
\t \t \t var promises[]; // Promises array
//Calling GET request for each URL
\t \t \t depthRange.foreach(function(depth){
var resourceUrl = urlService.buildSonarUrlsWithDept(depth);
\t \t \t promises.push($http.get(resourceUrl));
\t \t });
\t \t \t
//Resolving the promises array
\t \t \t $q.all(promises).then(function(results){
\t \t \t \t var metricData=[]; //Array for appending the data from all the requests
\t \t \t \t results.forEach(function(data){
\t \t \t \t \t metricData.push(data);
\t \t \t \t })
\t \t \t \t analyzeMutationData(metricData); //calling other function with collected data
\t \t \t \t });
\t \t };
错误处理程序在您的个人要求?你可以发布你现有的代码吗? – tymeJV
@tymeJV:请找到代码。 – Dravidian