mirror of
https://github.com/dawidd6/action-send-mail.git
synced 2026-05-06 17:30:35 +07:00
* Initial plan * Run npm ci --ignore-scripts to update dependencies Co-authored-by: dawidd6 <9713907+dawidd6@users.noreply.github.com> * Convert CommonJS to ESM (#255) * Initial plan * Convert CommonJS imports to ESM Co-authored-by: dawidd6 <9713907+dawidd6@users.noreply.github.com> * Use node: protocol prefix for built-in modules Co-authored-by: dawidd6 <9713907+dawidd6@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: dawidd6 <9713907+dawidd6@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: dawidd6 <9713907+dawidd6@users.noreply.github.com>
46 lines
2.0 KiB
Markdown
46 lines
2.0 KiB
Markdown
# Class: RetryAgent
|
|
|
|
Extends: `undici.Dispatcher`
|
|
|
|
A `undici.Dispatcher` that allows to automatically retry a request.
|
|
Wraps a `undici.RetryHandler`.
|
|
|
|
## `new RetryAgent(dispatcher, [options])`
|
|
|
|
Arguments:
|
|
|
|
* **dispatcher** `undici.Dispatcher` (required) - the dispatcher to wrap
|
|
* **options** `RetryHandlerOptions` (optional) - the options
|
|
|
|
Returns: `ProxyAgent`
|
|
|
|
### Parameter: `RetryHandlerOptions`
|
|
|
|
- **retry** `(err: Error, context: RetryContext, callback: (err?: Error | null) => void) => void` (optional) - Function to be called after every retry. It should pass error if no more retries should be performed.
|
|
- **maxRetries** `number` (optional) - Maximum number of retries. Default: `5`
|
|
- **maxTimeout** `number` (optional) - Maximum number of milliseconds to wait before retrying. Default: `30000` (30 seconds)
|
|
- **minTimeout** `number` (optional) - Minimum number of milliseconds to wait before retrying. Default: `500` (half a second)
|
|
- **timeoutFactor** `number` (optional) - Factor to multiply the timeout by for each retry attempt. Default: `2`
|
|
- **retryAfter** `boolean` (optional) - It enables automatic retry after the `Retry-After` header is received. Default: `true`
|
|
-
|
|
- **methods** `string[]` (optional) - Array of HTTP methods to retry. Default: `['GET', 'PUT', 'HEAD', 'OPTIONS', 'DELETE']`
|
|
- **statusCodes** `number[]` (optional) - Array of HTTP status codes to retry. Default: `[429, 500, 502, 503, 504]`
|
|
- **errorCodes** `string[]` (optional) - Array of Error codes to retry. Default: `['ECONNRESET', 'ECONNREFUSED', 'ENOTFOUND', 'ENETDOWN','ENETUNREACH', 'EHOSTDOWN', 'UND_ERR_SOCKET']`
|
|
|
|
**`RetryContext`**
|
|
|
|
- `state`: `RetryState` - Current retry state. It can be mutated.
|
|
- `opts`: `Dispatch.DispatchOptions & RetryOptions` - Options passed to the retry handler.
|
|
|
|
Example:
|
|
|
|
```js
|
|
import { Agent, RetryAgent } from 'undici'
|
|
|
|
const agent = new RetryAgent(new Agent())
|
|
|
|
const res = await agent.request('http://example.com')
|
|
console.log(res.statuCode)
|
|
console.log(await res.body.text())
|
|
```
|