当第一个observable得到错误400时,我想调用第二个observable。
this.service.runTest(resource)
.subscribe(
response => console.log(response),
err => {
this.service.runTest2(resource)
.subscribe(
response => {
setTimeout(()=>{this.resultDisplay = response}, 4000);
},
err => console.log(err)
)
}
);
答案 0 :(得分:1)
尝试使用catch运算符来捕获错误并做出相应的反应:
this.service.runTest(resource)
.catch(err =>
(err.status === 400)
? this.service.runTest2(resource).delay(4000)
: Observable.throw(err))
.subscribe(
response => console.log(response),
err => err => console.log(err));