0

I have a scenario where the initial request will send a url path and the subsequent request should make use of that path as the url to be hit using get request from service. (This part is done)

Now the actual issue starts , the problem here is that the 2nd request will not give the output directly rather it will send the status as QUEUE until the response is fully processed. All I have to do is to wait/hit the url again until QUEUE state is changed to OK state (Actual response comes here).

Code for 2nd request :

getOriginalData(url:any){

  const proxyRequest=this._getRequest(url)

  return proxyRequest
  .expand(response => {
      if (response.uuid==null) {
        this._getRequest(url);
      } else {
        Rx.Observable.empty();
      }
    return Observable.of(response);
  });

private _getRequest(url:any){
  return this._http.get(url)
}

I have been following this implementation to achieve my goal : Angular - Correctly using RXJS expand operator to make recursive http calls .

Using this implementation results in

ERROR RangeError: Maximum call stack size exceeded

But for some reason , it is not working as expected. How can I make a recursive call in a standard way such that it doesn't flood the network.

Am Novice
  • 325
  • 2
  • 9
  • 21

1 Answers1

1

Never used expand operator but from what I've understand you need to return an Observable.empty to stop the recursive request

Martin Choraine
  • 2,296
  • 3
  • 20
  • 37
  • But the request gets failed due to Stack error though – Am Novice May 15 '18 at 15:52
  • 1
    You haven't returned the observable.empty so the expand didn't stop – Martin Choraine May 15 '18 at 15:53
  • I have changed it as follows `getOriginalData(url:any){ const proxyRequest=this._getRequest(url) return proxyRequest .expand(response => { if (response.uuid==null) { return this._getRequest(url); } else { return Rx.Observable.empty(); } });` But its kind of going on forever without getting the final output – Am Novice May 15 '18 at 16:17
  • So try to debug to look what response is returning. Maybe response.uuid is always null and the function keep going to call http request – Martin Choraine May 15 '18 at 16:30