Skip to content

isRetryableHttpError

isRetryableHttpError(err): boolean

Determines whether an HTTP error (or generic error) should be retried.

  • Never retry on:
    • 2xx (success) responses
    • 3xx (redirect) responses
  • Retry on:
    • 408 (Request Timeout)
    • 429 (Too Many Requests)
    • Any 5xx (server error) responses
    • Anyhing without a numeric status property

unknown

The error to inspect. May be an Error with an optional numeric status field.

boolean

true if the error is retryable, otherwise false.

// Retry on 500 server error
isRetryableHttpError({ status: 500 }) // → true
// Do not retry on 404 Not Found
isRetryableHttpError({ status: 404 }) // → false
// Retry on network or other non-HTTP errors
isRetryableHttpError(new Error('network')) // → true