Skip to content

Is it possible to define different retry behavior per HTTP method? #1499

Answered by Giotino
kobik asked this question in Q&A
Discussion options

You must be logged in to vote

I don't think there's any intention to implement something like that because whats you're trying to achieve can be done easily. My previous example wasn't accounting for the retry delay that a request should have (in some cases), take a look at this new example.

(this is probably what you were describing in your comment)

const postErrorCodes = [
  'ECONNRESET',
  'EADDRINUSE',
  'ECONNREFUSED',
  'EPIPE',
  'ENOTFOUND',
  'ENETUNREACH',
  'EAI_AGAIN'
];

const instance = got.extend({
  retry: {
    // return 0 means no retry
    calculateDelay: ({error, computedValue}) => {
      if (error.options.method === 'POST')
        return postErrorCodes.includes(error.code!) ? computedValue : 0;

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

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

You must be logged in to vote
0 replies
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
Converted from issue

This discussion was converted from issue #1499 on December 10, 2020 17:08.