0

My requirement is pretty simple. I need to wait for a particular rest api() call to give success status code Once that particular rest api is successful, I need to perfom some other action. My restapi will give positive status only after some time(dynamic in nature)

this.httpClient.get('someurl').pipe(
  retryWhen(err =>
    err.pipe(
      concatMap(err => {

        // here we can check the error.
        // We can specify the retry only if it is throwing  404 error.
        // 404 ---- job is still runnig 
        console.log(err.status)
        if (err.status === 404) {
          console.log('Job is not yet completed ')
          return of(err);
        }
        // in other cases we throw an error down the pipe
        console.log('Returning another error ')
        return throwError(err);
      }),
      delay(1000),
      // we can keep calling forever but usually we want to avoid this.
      // So, we set the number of attempts including the initial one.
      //o => concat(o, throwError(`Sorry, there was no result after 3 retries)`))
    )
  ))

The above code is executing until it gives 200 response, but that particular response somehow I couldn't get hold of it

I need some logic where I can place once the rest api is successful

denolk
  • 765
  • 14
  • 27

0 Answers0