Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/383.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript catchError取消所有并行请求_Javascript_Angular_Redux_Rxjs_Ngrx - Fatal编程技术网

Javascript catchError取消所有并行请求

Javascript catchError取消所有并行请求,javascript,angular,redux,rxjs,ngrx,Javascript,Angular,Redux,Rxjs,Ngrx,我同时提出了多个请求。然后我在超时时抛出错误 getAllDirections() { ... return from(urls).pipe( // a list of api urls mergeMap((urlParam, index) => this.http.get<ISchedules>(urlParam[0]).pipe( map(dataRes => { return dataRes; }),

我同时提出了多个请求。然后我在超时时抛出错误

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}`);
      })
    )
  )
); 
getAllDirections(){
...
返回自(URL).pipe(//api URL的列表
合并映射((urlParam,index)=>
这个.http.get(urlParam[0]).pipe(
映射(dataRes=>{
返回数据存储;
}),
超时(6000),
catchError(错误=>{
console.log(错误);
返回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
          });
        })
      )
    )
  )
);
$LoadSchedulingsByDirectionsByBranch=createEffect(()=>
此.actions$管道(
ofType(ESchedulesActions.Type.),
合并映射(操作=>
this.apiCallsService.getAllDirections(action.payload,'2010-09-18')管道(
地图(行程=>({
类型:ESchedulesActions.TypeSuccess,
有效载荷:行程
})),
catchError(err=>{
控制台日志(err);
归还({
类型:ESchedulesActions.TypeFail,
有效载荷:错误
});
})
)
)
)
);
问题是,当它检测到第一次超时时,mergeMap停止,并且不处理其他调用。 因此,我只得到一个
console.log(error)
,而不是在每个http请求上都有错误。(只进入
catchError
一次)


在我的http网络开发工具上,我注意到当第一次超时发生时,所有并行请求都会被取消。

如果在
getAllDirections
中不执行catchError,它会工作吗?只是想知道,到目前为止,我觉得还可以……同样,似乎
catchError
是“kill”所有实际请求实际上,
throwError
会杀死源代码。您可以尝试它-
返回('Request timeout${error}')
和source将保持活动状态。当您返回错误时,它会弹出错误回调并关闭流。@dev我认为second
catchError
是用来捕获弹出的错误的。我只是想知道它是否真的收到了错误。我想他是否会返回(…)的
那么它肯定不会进入第二个
捕获错误
,而是由
映射处理operator@dev太好了!非常感谢