{
  "type": "module",
  "source": "doc/api/api-retryhandler.md",
  "modules": [
    {
      "textRaw": "Class: RetryHandler",
      "name": "class:_retryhandler",
      "type": "module",
      "desc": "<p>Extends: <code>undici.DispatcherHandlers</code></p>\n<p>A handler class that implements the retry logic for a request.</p>",
      "signatures": [
        {
          "textRaw": "`new RetryHandler(opts, { dispatch, handler })`",
          "name": "RetryHandler",
          "type": "ctor",
          "params": [
            {
              "name": "opts"
            },
            {
              "name": "{ dispatch"
            },
            {
              "name": "handler }"
            }
          ],
          "desc": "<p>Arguments:</p>\n<ul>\n<li><strong>opts</strong> <code>Dispatch.DispatchOptions &#x26; { retryOptions?: RetryOptions }</code> (required) - An intersection of <code>Dispatcher.DispatchOptions</code> and an optional <code>RetryOptions</code> object.</li>\n<li><strong>{ dispatch, handler }</strong> <code>RetryHandlers</code> (required) - Object containing the <code>dispatch</code> to be used on every retry, and <code>handler</code> for handling the <code>dispatch</code> lifecycle.</li>\n</ul>\n<p>Returns: <code>retryHandler</code></p>",
          "modules": [
            {
              "textRaw": "Parameter: `Dispatch.DispatchOptions & RetryOptions`",
              "name": "parameter:_`dispatch.dispatchoptions_&_retryoptions`",
              "type": "module",
              "desc": "<p>Extends: <a href=\"/docs/docs/api/Dispatcher.html#parameter-dispatchoptions\"><code>Dispatch.DispatchOptions</code></a>.</p>",
              "modules": [
                {
                  "textRaw": "`RetryOptions`",
                  "name": "`retryoptions`",
                  "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.</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><strong><code>RetryState</code></strong></p>\n<p>It represents the retry state for a given request.</p>\n<ul>\n<li><code>counter</code>: <code>number</code> - Current retry attempt.</li>\n</ul>",
                  "displayName": "`RetryOptions`"
                }
              ],
              "displayName": "Parameter: `Dispatch.DispatchOptions & RetryOptions`"
            },
            {
              "textRaw": "Parameter `RetryHandlers`",
              "name": "parameter_`retryhandlers`",
              "type": "module",
              "desc": "<ul>\n<li><strong>dispatch</strong> <code>(options: Dispatch.DispatchOptions, handlers: Dispatch.DispatchHandler) => Promise&#x3C;Dispatch.DispatchResponse></code> (required) - Dispatch function to be called after every retry.</li>\n<li><strong>handler</strong> Extends <a href=\"/docs/docs/api/Dispatcher.html#dispatcherdispatchoptions-handler\"><code>Dispatch.DispatchHandler</code></a> (required) - Handler function to be called after the request is successful or the retries are exhausted.</li>\n</ul>\n<blockquote>\n<p><strong>Note</strong>: The <code>RetryHandler</code> does not retry over stateful bodies (e.g. streams, AsyncIterable) as those, once consumed, are left in a state that cannot be reutilized. For these situations the <code>RetryHandler</code> will identify\nthe body as stateful and will not retry the request rejecting with the error <code>UND_ERR_REQ_RETRY</code>.</p>\n</blockquote>\n<p>Examples:</p>\n<pre><code class=\"language-js\">const client = new Client(`http://localhost:${server.address().port}`);\nconst chunks = [];\nconst handler = new RetryHandler(\n  {\n    ...dispatchOptions,\n    retryOptions: {\n      // custom retry function\n      retry: function (err, state, callback) {\n        counter++;\n\n        if (err.code &#x26;&#x26; err.code === \"UND_ERR_DESTROYED\") {\n          callback(err);\n          return;\n        }\n\n        if (err.statusCode === 206) {\n          callback(err);\n          return;\n        }\n\n        setTimeout(() => callback(null), 1000);\n      },\n    },\n  },\n  {\n    dispatch: (...args) => {\n      return client.dispatch(...args);\n    },\n    handler: {\n      onRequestStart() {},\n      onBodySent(chunk) {},\n      onResponseStart(_controller, status, headers) {\n        // do something with headers\n      },\n      onResponseData(_controller, chunk) {\n        chunks.push(chunk);\n      },\n      onResponseEnd() {},\n      onResponseError(_controller, err) {\n        // handle error properly\n      },\n    },\n  }\n);\n</code></pre>",
              "modules": [
                {
                  "textRaw": "Example - Basic RetryHandler with defaults",
                  "name": "example_-_basic_retryhandler_with_defaults",
                  "type": "module",
                  "desc": "<pre><code class=\"language-js\">const client = new Client(`http://localhost:${server.address().port}`);\nconst handler = new RetryHandler(dispatchOptions, {\n  dispatch: client.dispatch.bind(client),\n  handler: {\n    onRequestStart() {},\n    onBodySent(chunk) {},\n    onResponseStart(_controller, status, headers) {},\n    onResponseData(_controller, chunk) {},\n    onResponseEnd() {},\n    onResponseError(_controller, err) {},\n  },\n});\n</code></pre>",
                  "displayName": "Example - Basic RetryHandler with defaults"
                }
              ],
              "displayName": "Parameter `RetryHandlers`"
            }
          ]
        }
      ],
      "displayName": "Class: RetryHandler"
    }
  ]
}