angular - 在角度中使用“retrywhen”打印成功响应的最佳方法
问题描述
我的要求很简单。我需要等待特定的 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 成功,我需要一些可以放置的逻辑
解决方案
推荐阅读
- javascript - 如果键有多个单词,如何从 Firebase Realtime DB 查询数据?
- javascript - 如何在父子组件之间使用回调函数
- sql - 根据开始和结束数字生成行?
- python - 如果“key”中有空格,Python s3 copy_from 会失败。如何搜索文件内容,然后使用 python 打印存储在 S3 中的文件名
- r - 使用 Windows 批处理自动化使用 ODBC 的 R 脚本
- nginx - Nginx 配置只匹配基本路径,否则返回 404。为什么?
- ftp - 我怎样才能大规模安装 PrestaShop 模块?
- python - 美化文件夹中的所有python脚本
- reactjs - CloudFlare JS 挑战正在打破我的 SPA
- razor-pages - asp-for 不在 Razor 页面上生成代码