Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for if-match on retry handler #3144

Merged
merged 7 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
docs: add documentation and types
  • Loading branch information
metcoder95 committed Apr 25, 2024
commit 917f5aea700e3e86d9b8f3b1ff6c3802394e5b59
1 change: 1 addition & 0 deletions docs/docs/api/RetryHandler.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Extends: [`Dispatch.DispatchOptions`](Dispatcher.md#parameter-dispatchoptions).
- **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']`
- **ifMatch** `boolean` (optional) - It enables the send of `if-match` pre-condition header if `etag` is present in the first response. Default: `true`
metcoder95 marked this conversation as resolved.
Show resolved Hide resolved

**`RetryContext`**

Expand Down
2 changes: 1 addition & 1 deletion test/types/retry-agent.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { RetryAgent, Agent } from '../..'
const dispatcher = new Agent()

expectAssignable<RetryAgent>(new RetryAgent(dispatcher))
expectAssignable<RetryAgent>(new RetryAgent(dispatcher, { maxRetries: 5 }))
expectAssignable<RetryAgent>(new RetryAgent(dispatcher, { maxRetries: 5, ifMatch: false }))

{
const retryAgent = new RetryAgent(dispatcher)
Expand Down
7 changes: 7 additions & 0 deletions types/retry-handler.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ declare namespace RetryHandler {
* @default [500, 502, 503, 504, 429],
*/
statusCodes?: number[];
/**
* Enables/disabled the usage of `If-Match` pre-condition header for retry requests.
* @type {boolean}
* @memberof RetryOptions
* @default true
*/
ifMatch?: boolean;
}

export interface RetryHandlers {
Expand Down
Loading