我以为这些年来我已经在以前的项目中弄清楚了这一切......显然不是。
Goal : Take Service that calls other Services and if there is any type of error being returned ( not a status of 200 ) then I need the async thing to be waiting and not proceeding.
在我看来,我从来没有见过那么好的例子,因为它都非常简单。
我阅读了各种关于 Angular (1) 在幕后所做的事情的文章,我看到有 $q、.then、.success 等。
似乎我遇到了问题return
以及在没有任何问题检查的情况下进行其他嵌套和捆绑服务调用。
本质上这张图片显示了正在返回的内容
数据:null(这很糟糕)
错误列表数组10“此订单无法提交...”(也很糟糕)
hasErrors : true (也不好)
因此,数据对我来说很重要,需要捕获并显示给用户,然后不要进行更多处理
这是我的操作顺序
this.submitEnrollment = function (enrollment) {
return getSubmit(requestData);
}
// Which CALLS below
var getSubmit = function (request) {
return SparkRequestService
.submitRequest(request)
.then(
function (resData) {
console.log("resData", resData);
enrollmentService.resetEnrollment();
return resData;
},
function (resData) {
console.log('error');
}
);
}
那我当然会打电话SparkRequestService.submitRequest(request)
但根据所附图片,我收到错误resData
所以看来我有必要去询问一下resData
正确的?那么我真的不应该允许调用其他服务enrollmentService.resetEnrollment();
我如何重构以停止处理? if 语句中.then
?