Search code examples
apolloapollo-clientvue-apollo

unexpected behavior of apollo link retry on 400 error


description: Attempt an operation multiple times if it fails due to network or server errors.

I have used apollo-link-retry to retry calls on the occurrence of server errors(5xx). But when 400 error(bad request) is occurring it retrying which is expected to retry in server error only. Does network error means all client errors(4xx) and server errors(5xx)? How to stop retrying on errors other than 5xx?


Solution

  • In the context of Apollo Client, there are two types of errors -- GraphQL errors (those returned inside the errors array in the response) and network errors. Any request that returns a status other than 200 is considered to have encountered a network error. The default RetryLink configuration is not that granular -- it only cares about whether a network error occurred, not what kind of error occurred. If you want to not retry on certain errors, provide a retryIf function to the attempts configuration as shown in the docs:

      attempts: {
        retryIf: (error, _operation) => {
          // return true or false depending on the properties on error
        }
      }
    })