# @mimik/request-retry

> Request retry wrapping axios

Latest version **4.1.1** (published 2026-07-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install @mimik/request-retry
pnpm add @mimik/request-retry
yarn add @mimik/request-retry
bun add @mimik/request-retry
```

## Health

**Score 60/100 (C)** — status: active.

Positive: esm support; no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 4.1.1 |
| Published | 2026-07-08 |
| First published | 2019-09-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=24.0.0 |
| Dependencies | 5 |
| Unpacked size | 28.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | mimik technology inc |
| Maintainers | mimik-npm-editor, hofachiang, miburger, mimikopensource, sasan.raisdana |
| Keywords | mimik, microservice |

## Links

- npm: https://www.npmjs.com/package/@mimik/request-retry
- Repository: https://bitbucket.org/mimiktech/request-retry
- Homepage: https://bitbucket.org/mimiktech/request-retry#readme
- Issues: https://bitbucket.org/mimiktech/request-retry/issues
- npm.io page: https://npm.io/package/@mimik/request-retry

## Dependencies (5)

- [axios](https://npm.io/package/axios.md) 1.18.0
- [bluebird](https://npm.io/package/bluebird.md) 3.7.2
- [@mimik/request-helper](https://npm.io/package/@mimik/request-helper.md) ^2.0.8
- [@mimik/response-helper](https://npm.io/package/@mimik/response-helper.md) ^4.1.1
- [@mimik/sumologic-winston-logger](https://npm.io/package/@mimik/sumologic-winston-logger.md) ^2.3.1

## Recent versions

- 4.1.1 (latest) — 2026-07-08
- 4.0.12 — 2026-03-22
- 4.0.11 — 2026-03-17
- 4.0.10 — 2026-03-12
- 4.0.9 — 2026-02-23
- 4.0.8 — 2026-02-23
- 4.0.7 — 2026-02-16
- 4.0.6 — 2025-09-19
- 4.0.5 — 2025-09-14
- 4.0.4 — 2025-09-14
- 4.0.3 — 2025-07-19
- 4.0.2 — 2025-07-18
- 4.0.1 — 2025-03-26
- 4.0.0 — 2025-03-26
- 3.0.2 — 2024-10-05
- … 16 more at https://npm.io/package/@mimik/request-retry/versions

## README

## Modules

<dl>
<dt><a href="#module_request-retry">request-retry</a></dt>
<dd></dd>
</dl>

## Functions

<dl>
<dt><a href="#redactOptions">redactOptions(options)</a> ⇒ <code>object</code></dt>
<dd><p>Build a shallow copy of the request options with sensitive values redacted,
safe to log or embed in errors. Redacts <code>headers.authorization</code>,
<code>headers.cookie</code> and the axios <code>auth</code> credentials.</p>
</dd>
</dl>

<a name="module_request-retry"></a>

## request-retry
**Example**  
```js
import { rpRetry } from '@mimik/request-retry';
// or
import rp from '@mimik/request-retry';
```
<a name="module_request-retry..rpRetry"></a>

### request-retry~rpRetry(options) ⇒ <code>Promise.&lt;\*&gt;</code>
Make a request with retries.

**Kind**: inner method of [<code>request-retry</code>](#module_request-retry)  
**Returns**: <code>Promise.&lt;\*&gt;</code> - A bluebird promise (supports cancellation).  
**Category**: async  
**Throws**:

- <code>Error</code> An error produced by `getRichError`, wrapping an
[Axios](https://www.npmjs.com/package/axios) error or a `TimeoutError`.

The **default** `retryStrategy` is:

```javascript
defaultRetry = (...args) => {
  const { statusCode } = args[1]; // err
  // Retry on 5xx and 429. If there is no statusCode, retry unless it's an "Invalid URI" error.
  return (statusCode && (Math.floor(statusCode / 100) === 5 || statusCode === 429))
         || (!statusCode && !args[1].message.includes('Invalid URI'));
};
```

If not already set, the `User-Agent` header is set to:
`mimik-{serverType}/{serverVersion}/{serverId} {architecture} {node}`.

To ease migration from `request-promise`, the following adjustments are applied to `options`:
- `uri` takes precedence over `url`.
- If `json` is an object, `body` takes precedence over `json`; both are mapped to Axios `data`.
- `qs` is mapped to Axios `params`.

**Requires**: <code>module:@mimik/sumologic-winston-logger</code>, <code>module:@mimik/response-helper</code>  
**Fulfil**: <code>object</code> - The Axios response when `resolveWithFullResponse` is `true`; otherwise `response.data`.  

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| options | <code>object</code> |  | Options for the request (similar to [axios](https://www.npmjs.com/package/axios)). The `validateStatus` option is disabled: an error is thrown for status codes outside **[200, 300)**. An additional option, `resolveWithFullResponse`, controls the return shape: when `true`, the full Axios response object is returned; when `false` or omitted, only `response.data` is returned. |
| [options.retry] | <code>object</code> |  | Retry configuration. |
| [options.retry.retries] | <code>number</code> | <code>2</code> | Maximum number of retries, independent of the `retryStrategy`. If the value is `< 0`, it is set to `0`; if `> 15`, it is set to `15`. |
| [options.retry.delay] | <code>number</code> | <code>1000</code> | Delay between retries in milliseconds when no `delayStrategy` is provided. If the value is `< 20`, it is set to `20`; if `> 30000`, it is set to `30000`. |
| [options.retry.delayStrategy] | <code>function</code> |  | A function that returns the delay (in milliseconds) to wait before the next retry. Signature: `(nbRetry, err, options, correlationId)`. Must return a number `> 0` and `<= 30000`; otherwise `delay` is used. |
| [options.retry.retryStrategy] | <code>function</code> |  | A function that decides whether to retry. Signature: `(nbRetry, err, options, correlationId)`. Should return a boolean; if it throws or returns a non-boolean, a retry is forced (`true`). A non-function value is replaced by `unknownRetry`, which always retries. |
| [options.retry.timeout] | <code>number</code> | <code>50</code> | Request timeout (in seconds) applied to the initial request and all retries. If reached, a `TimeoutError` is thrown. Values `< 10` are set to `10`; values `> 120` are set to `120`. |
| [options.retry.logLevel] | <code>object</code> |  | Controls logging behavior. When omitted, requests and responses are logged at `info` with full details, and errors at `warn`. When provided but incomplete, only the provided keys are active; missing keys disable that logging. Non-object values are ignored and defaults apply. |
| [options.retry.logLevel.response] | <code>string</code> |  | Log level for responses. Invalid values fall back to `silly`. |
| [options.retry.logLevel.error] | <code>string</code> |  | Log level for errors. Invalid values fall back to `silly`. |
| [options.retry.logLevel.request] | <code>string</code> |  | Log level for requests. Invalid values fall back to `silly`. |
| [options.retry.logLevel.responseDetails] | <code>string</code> | <code>&quot;&#x27;type&#x27;&quot;</code> | Detail level for the response: `count`, `type`, or `full`. Invalid values fall back to `type`. When `logLevel` is omitted entirely, the default is `full`. |
| [options.retry.logLevel.responseName] | <code>string</code> | <code>&quot;&#x27;response&#x27;&quot;</code> | Label associated with the response. Non-string or empty values fall back to `response`. |
| [options.metrics] | <code>object</code> |  | Metrics configuration. |
| [options.metrics.HTTPRequestDuration] | <code>object</code> |  | A `prom-client` metric object (e.g. a Histogram) used to measure request duration; the code calls `.labels(...).observe(...)` on it. |
| [options.metrics.url] | <code>string</code> |  | Optional URL label for the metric. If omitted, the request URL is used. |

<a name="redactOptions"></a>

## redactOptions(options) ⇒ <code>object</code>
Build a shallow copy of the request options with sensitive values redacted,
safe to log or embed in errors. Redacts `headers.authorization`,
`headers.cookie` and the axios `auth` credentials.

**Kind**: global function  
**Returns**: <code>object</code> - A copy with sensitive fields replaced by `[REDACTED]`.  

| Param | Type | Description |
| --- | --- | --- |
| options | <code>object</code> | The (already user-agent-stamped) request options. |

---
_Source: https://npm.io/package/@mimik/request-retry · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
