{
  "type": "module",
  "source": "doc/api/api-retryagent.md",
  "modules": [
    {
      "textRaw": "Class: RetryAgent",
      "name": "class:_retryagent",
      "type": "module",
      "desc": "<p>Extends: <code>undici.Dispatcher</code></p>\n<p>A <code>undici.Dispatcher</code> that allows to automatically retry a request.\nWraps a <code>undici.RetryHandler</code>.</p>",
      "signatures": [
        {
          "textRaw": "`new RetryAgent(dispatcher, [options])`",
          "name": "RetryAgent",
          "type": "ctor",
          "params": [
            {
              "name": "dispatcher"
            },
            {
              "name": "options",
              "optional": true
            }
          ],
          "desc": "<p>Arguments:</p>\n<ul>\n<li><strong>dispatcher</strong> <code>undici.Dispatcher</code> (required) - the dispatcher to wrap</li>\n<li><strong>options</strong> <code>RetryHandlerOptions</code> (optional) - the options</li>\n</ul>\n<p>Returns: <code>RetryAgent</code></p>",
          "modules": [
            {
              "textRaw": "Parameter: `RetryHandlerOptions`",
              "name": "parameter:_`retryhandleroptions`",
              "type": "module",
              "desc": "<ul>\n<li><strong>throwOnError</strong> <code>boolean</code> (optional) - Disable to prevent throwing error on last retry attept, useful if you need the body on errors from server or if you have custom error handler. Default: <code>true</code></li>\n<li><strong>retry</strong> <code>(err: Error, context: RetryContext, callback: (err?: Error | null) => void) => void</code> (optional) - Function to be called after every retry. It should pass error if no more retries should be performed.</li>\n<li><strong>maxRetries</strong> <code>number</code> (optional) - Maximum number of retries. Default: <code>5</code></li>\n<li><strong>maxTimeout</strong> <code>number</code> (optional) - Maximum number of milliseconds to wait before retrying. Default: <code>30000</code> (30 seconds)</li>\n<li><strong>minTimeout</strong> <code>number</code> (optional) - Minimum number of milliseconds to wait before retrying. Default: <code>500</code> (half a second)</li>\n<li><strong>timeoutFactor</strong> <code>number</code> (optional) - Factor to multiply the timeout by for each retry attempt. Default: <code>2</code></li>\n<li><strong>retryAfter</strong> <code>boolean</code> (optional) - It enables automatic retry after the <code>Retry-After</code> header is received. Default: <code>true</code></li>\n<li><strong>methods</strong> <code>string[]</code> (optional) - Array of HTTP methods to retry. Default: <code>['GET', 'HEAD', 'OPTIONS', 'PUT', 'DELETE', 'TRACE']</code></li>\n<li><strong>statusCodes</strong> <code>number[]</code> (optional) - Array of HTTP status codes to retry. Default: <code>[429, 500, 502, 503, 504]</code></li>\n<li><strong>errorCodes</strong> <code>string[]</code> (optional) - Array of Error codes to retry. Default: <code>['ECONNRESET', 'ECONNREFUSED', 'ENOTFOUND', 'ENETDOWN', 'ENETUNREACH', 'EHOSTDOWN', 'EHOSTUNREACH', 'EPIPE', 'UND_ERR_SOCKET']</code></li>\n</ul>\n<p><strong><code>RetryContext</code></strong></p>\n<ul>\n<li><code>state</code>: <code>RetryState</code> - Current retry state. It can be mutated.</li>\n<li><code>opts</code>: <code>Dispatch.DispatchOptions &#x26; RetryOptions</code> - Options passed to the retry handler.</li>\n</ul>\n<p>Example:</p>\n<pre><code class=\"language-js\">import { Agent, RetryAgent } from 'undici'\n\nconst agent = new RetryAgent(new Agent())\n\nconst res = await agent.request({\n  method: 'GET',\n  origin: 'http://example.com',\n  path: '/',\n})\nconsole.log(res.statusCode)\nconsole.log(await res.body.text())\n</code></pre>",
              "displayName": "Parameter: `RetryHandlerOptions`"
            }
          ]
        }
      ],
      "displayName": "Class: RetryAgent"
    }
  ]
}