Skip to content

Best way to implement "retry on 404" #1781

Discussion options

You must be logged in to vote

Given that afterResponse is not triggered by retryWithMergedOptions, the solution is in fact straightforward and dead simple:

  const defaultOptions: ExtendOptions = {
    hooks: {
      afterResponse: [
        async (response, retryWithMergedOptions) => {
          const {statusCode} = response;

          if (statusCode === 404) {
            const reset = await resetConnectionPool();
            console.error('!!!', 'resetConnectionPool', reset.statusCode);
            return retryWithMergedOptions({});
          }

          return response;
        },
      ],
    },
    pagination: {paginate, transform, stackAllItems: false},
    responseType: 'json',
    ...authOptions,
  };

  re…

Replies: 3 comments 7 replies

Comment options

You must be logged in to vote
3 replies
@PopGoesTheWza
Comment options

@szmarczak
Comment options

@PopGoesTheWza
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by PopGoesTheWza
Comment options

You must be logged in to vote
4 replies
@szmarczak
Comment options

@PopGoesTheWza
Comment options

@ruslan-ncg
Comment options

@ruslan-ncg
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants
Converted from issue

This discussion was converted from issue #1780 on July 13, 2021 15:22.