javascript - catchError 取消所有并行请求
问题描述
我并行提出了多个请求。然后我在超时时抛出错误。
getAllDirections() {
...
return from(urls).pipe( // a list of api urls
mergeMap((urlParam, index) =>
this.http.get<ISchedules>(urlParam[0]).pipe(
map(dataRes => {
return dataRes;
}),
timeout(6000),
catchError(error => {
console.log(error);
return throwError(`Request timeout ${error}`);
})
)
)
);
然后在我的效果中,我捕获了错误
$LoadSchedulingsByDirectionsByBranch = createEffect(() =>
this.actions$.pipe(
ofType<any>(ESchedulesActions.Type..),
mergeMap(action =>
this.apiCallsService.getAllDirections(action.payload, '2010-09-18').pipe(
map(trips => ({
type: ESchedulesActions.TypeSuccess,
payload: trips
})),
catchError(err => {
console.log(err);
return of({
type: ESchedulesActions.TypeFail,
payload: err
});
})
)
)
)
);
问题是当它检测到第一次超时时,mergeMap停止并且不处理其他调用。结果,我只得到一个console.log(error)
,而不是在每个 http 请求上都有错误。(只能进去catchError
一次)
在我的 http 网络 devtools 上,我注意到当第一次超时发生时,所有并行请求都被取消。
解决方案
推荐阅读
- python - ValueError:SavedModel 的 SignatureDefs 中没有“serving_default”。可能的值为 ''
- c - 在函数 2D DMA 中传递地址
- java - @Transactional 回滚在 SpringBoot 中不起作用
- laravel - 渲染期间应用程序区域设置加密的未知原因?
- python - 列未使用此 groupby 转换填充缺失值
- sql - 将查询结果导出到excel
- azure - Azure B2C 的自定义用户管理
- javascript - 如何在ejs中替换unicode
- c# - 415(不支持的媒体类型)Angular API 调用
- marko - MarkoJS 组件中“无法读取未定义的属性'insertInto'”错误的原因是什么?