我的要求很简单。我需要等待特定的 rest api() 调用以提供成功状态代码一旦特定的 rest api 成功,我需要执行一些其他操作。我的restapi只会在一段时间后给出积极的状态(本质上是动态的)
this.httpClient.get('someurl').pipe(
retryWhen(err =>
err.pipe(
concatMap(err => {
// here we can check the error.
// We can specify the retry only if it is throwing 404 error.
// 404 ---- job is still runnig
console.log(err.status)
if (err.status === 404) {
console.log('Job is not yet completed ')
return of(err);
}
// in other cases we throw an error down the pipe
console.log('Returning another error ')
return throwError(err);
}),
delay(1000),
// we can keep calling forever but usually we want to avoid this.
// So, we set the number of attempts including the initial one.
//o => concat(o, throwError(`Sorry, there was no result after 3 retries)`))
)
))
上面的代码一直在执行,直到它给出 200 响应,但是那个特定的响应不知何故我无法掌握它
一旦其余 api 成功,我需要一些可以放置的逻辑