问题
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