function users(userService, helperService) {
return userService.get()
.then(function(){})
.catch(function (errors) {
if (angular.isArray(errors)) {
for (var i = errors.length - 1; i > -1; i--) {
console.log(errors[i]);
}
}
window.alert('unable to get data');
});
}
function get() {
return dataService.get("users").then(function (data) {
if (....) {
return data
}
else {
throw new Error('error in userService')
}
}).catch(helperService.ErrorHandler('error in userService'));
}
function get(endpoint, data) {
return $http.get(API_URL + endpoint).then(function (data) {
if (status check) {
return data;
}
else {
throw new Error('error in dataService')
}
}).catch(helperService.ErrorHandler('error in dataService'));
}
function ErrorHandler (error) {
};
我需要为所有catch块编写单个ErrorHandler函数并将数组返回给userComponent.js ..(使用javascript闭包和提升属性..)