Skip to content

I want to skip retry when specific error is thrown #7385

Answered by demensky
ridvandmrc asked this question in Q&A
Discussion options

You must be logged in to vote

I think you need to pass the function to the delay parameter.

retry({
  delay: (error) => {
    console.log(error);

    if (error instanceof Error && error.message === 'lol') {
      // some specific error
      throw error;
    }

    return timer(1000); // or `of(null)` for immediate
  },
})
Full example
import { defer, retry, timer } from 'rxjs';

const names = ['foo', 'bar', 'lol', 'kek'];

defer(() => {
  throw new Error(names.shift());
})
  .pipe(
    retry({
      delay: (error) => {
        console.log(error);

        if (error instanceof Error && error.message === 'lol') {
          // some specific error
          throw error;
        }

        return timer(1000); // or `of(…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ridvandmrc
Comment options

Answer selected by benlesh
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