angularjs - return an error from $http.success -
i working in angular , need signify error promise further down chain when result being resolved in .success().
i call function in service controller
myservice.myfunction().then( function(results){ // success stuff }, function(err){ // failure stuff });
myfunction like
myfunction(){ return $http.get('url') .success(function(results){}) .error(function(err){}) }
based on conditions, need have .then() execute errorcallback though $http.get().success() triggered. how can make $http received error?
some fixes need achieve use then
instead of success
function on $http
.
and in then
success callback can return $q.reject(errordata)
reject promise down chain.
return $http.get('url').then(function(results){ if(condition) { return $q.reject(errordata); } return result.data; //then callback object properties },function(error) { return $q.reject(error); })
success
returns original $http
promise whereas then
returns promise gets resolved return value of success , error callback.
Comments
Post a Comment