Returnning "null" response from rxjs Obserable when calling a time consuming REST endpoint by Angular HttpClient

Viewed 55

I used Angular HttpClient to send a http "GET" request to a Springboot REST endpoint, in my code, I wrap the response by Observable. e.g.

public getDataFromXBackend(params: Request2Backend): Observable<ResponseFromBackend> {
  const url = `https://xxx/getData?${parse(params)}`;
  return this.httpClient.get<ResponseFromBackend>(url);
}

A state class will call the "getDataFromXBackend" function as below:

showData({patchState, dispatch, getState}: StateContext<XXModle>) {
   return this.prepareParams(getState()).pipe(
   switchMap(params => this.service.getDataFromXBackend(params),
   switchMap(response => dispatch(new ShowDataSuccess(response.list))),
   catchError(e => dispatch(new HandleError(e)))
   );
}

The issue is that the "response" variable in the second switchMap would be 'null' when the backend service took long time to return a large response. However, everything is working fine when a smaller response return in a short time.

I took whole day to find out the root cause, but with no luck...

Is it possible due to TCP connection closed by the peer? And how to enhance the code to solve such issue?

0 Answers
Related