Skip to content

How to Retry http requests in Angular Interceptor ONLY when user clicks a button #7175

Answered by voliva
simon-chen-1 asked this question in Q&A
Discussion options

You must be logged in to vote

The retry operator receives an ObservableInput (an observable or anything that can transform into an observable) on the delay function, that tells it when to retry it.

Also, the throw 'Error thrown!!! shouldn't be there. This is just killing the operator. Is there a reason you wanted to throw something in there?

This should work:

  intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
    return next.handle(request)
      .pipe(
        retry({ delay: (error: HttpErrorResponse) => {
          // Code for the popup modal
          // We can just return the promise that Swal.fire emits - When it resolves we can either rethrow the error
          // (s…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@simon-chen-1
Comment options

Answer selected by simon-chen-1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants