catchError cancel all parallel requests

狂风中的少年 提交于 2020-03-04 17:37:27

问题


I made multiple requests in parallel. then I throw error when timeout.

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}`);
      })
    )
  )
); 

Then in my effect I capture the 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
          });
        })
      )
    )
  )
);

the issue is that when it detect the first timeout the mergeMap stops and don't treat other calls. As a result I get only one console.log(error) of instead having error on every http request. ( get inside catchError only one time )

On my http network devtools I notice that all the parallel requests are canceled when the first timeout occur.

来源:https://stackoverflow.com/questions/59953249/catcherror-cancel-all-parallel-requests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!