【发布时间】:2016-08-24 20:08:29
【问题描述】:
我无法更改端点,如果失败,它将返回带有不同数据的 200 OK 响应。如何让它运行错误函数(then 中的第二个函数来自承诺)?
MyService 服务:
self.getData = function() {
return $http.get('/api/controller/action').then(function(x) {
//This will be run even on failure. How can I call....
return x.data;
}, function(x) {
//......here, from the front-end, so that, the 2nd function in
//inside the 'then' in the controller is run.
//This code will currently never run as it never fails server side.
return x;
});
};
控制器:
MyService.getData().then(function(x) {
//Success
}, function(x) {
//Failure
});
【问题讨论】:
标签: javascript angularjs angularjs-directive angular-promise