@cedvict/http-guardian-plugin-retry
v0.5.0
Published
Retry plugin (exponential backoff) for http-guardian.
Downloads
869
Readme
@cedvict/http-guardian-plugin-retry
Retry plugin (exponential backoff) for http-guardian.
Install
npm i @cedvict/http-guardian-plugin-retryUsage
import { retryPlugin } from "@cedvict/http-guardian-plugin-retry";
const plugin = retryPlugin({
retries: 3,
baseDelayMs: 200,
maxDelayMs: 5_000,
jitter: "full",
});By default, only GET, HEAD, and OPTIONS requests are replayed. Network
errors and statuses 408, 429, 500, 502, 503, and 504 are retryable.
Retry-After is honored when present.
Structured retryability (MIC)
MIC error envelopes expose an explicit top-level retryable boolean. Use the
provided response classifier so that this backend decision takes precedence
over the status list:
import {
createApiParserStructured,
createHttpClient,
noAuth,
} from "@cedvict/http-guardian";
import {
retryableEnvelopeClassifier,
retryPlugin,
} from "@cedvict/http-guardian-plugin-retry";
const api = createHttpClient({
baseUrl: "https://api.example.com",
auth: noAuth(),
parser: createApiParserStructured(),
plugins: [
retryPlugin({
isRetryableResponse: retryableEnvelopeClassifier,
}),
],
});retryable: trueretries even when the status is absent fromretryOnStatuses.retryable: falseprevents a retry even when the status is in that list.- A missing or malformed hint falls back to
retryOnStatuses. - Request eligibility still applies first: non-idempotent methods are not
replayed unless
isRetryableRequestexplicitly allows them.
Custom classifiers receive a cloned Response, so they may read the body
without consuming the response later parsed by http-guardian. Return
undefined to preserve the status-based policy.
