@aws-sdk/middleware-retry
Advanced tools
Comparing version 3.226.0 to 3.229.0
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.AdaptiveRetryStrategy = void 0; | ||
const config_1 = require("./config"); | ||
const DefaultRateLimiter_1 = require("./DefaultRateLimiter"); | ||
const util_retry_1 = require("@aws-sdk/util-retry"); | ||
const StandardRetryStrategy_1 = require("./StandardRetryStrategy"); | ||
@@ -11,4 +10,4 @@ class AdaptiveRetryStrategy extends StandardRetryStrategy_1.StandardRetryStrategy { | ||
super(maxAttemptsProvider, superOptions); | ||
this.rateLimiter = rateLimiter !== null && rateLimiter !== void 0 ? rateLimiter : new DefaultRateLimiter_1.DefaultRateLimiter(); | ||
this.mode = config_1.RETRY_MODES.ADAPTIVE; | ||
this.rateLimiter = rateLimiter !== null && rateLimiter !== void 0 ? rateLimiter : new util_retry_1.DefaultRateLimiter(); | ||
this.mode = util_retry_1.RETRY_MODES.ADAPTIVE; | ||
} | ||
@@ -15,0 +14,0 @@ async retry(next, args) { |
@@ -5,5 +5,3 @@ "use strict"; | ||
const util_middleware_1 = require("@aws-sdk/util-middleware"); | ||
const AdaptiveRetryStrategy_1 = require("./AdaptiveRetryStrategy"); | ||
const config_1 = require("./config"); | ||
const StandardRetryStrategy_1 = require("./StandardRetryStrategy"); | ||
const util_retry_1 = require("@aws-sdk/util-retry"); | ||
exports.ENV_MAX_ATTEMPTS = "AWS_MAX_ATTEMPTS"; | ||
@@ -32,7 +30,8 @@ exports.CONFIG_MAX_ATTEMPTS = "max_attempts"; | ||
}, | ||
default: config_1.DEFAULT_MAX_ATTEMPTS, | ||
default: util_retry_1.DEFAULT_MAX_ATTEMPTS, | ||
}; | ||
const resolveRetryConfig = (input) => { | ||
var _a; | ||
const maxAttempts = (0, util_middleware_1.normalizeProvider)((_a = input.maxAttempts) !== null && _a !== void 0 ? _a : config_1.DEFAULT_MAX_ATTEMPTS); | ||
const { retryStrategy } = input; | ||
const maxAttempts = (0, util_middleware_1.normalizeProvider)((_a = input.maxAttempts) !== null && _a !== void 0 ? _a : util_retry_1.DEFAULT_MAX_ATTEMPTS); | ||
return { | ||
@@ -42,10 +41,10 @@ ...input, | ||
retryStrategy: async () => { | ||
if (input.retryStrategy) { | ||
return input.retryStrategy; | ||
if (retryStrategy) { | ||
return retryStrategy; | ||
} | ||
const retryMode = await (0, util_middleware_1.normalizeProvider)(input.retryMode)(); | ||
if (retryMode === config_1.RETRY_MODES.ADAPTIVE) { | ||
return new AdaptiveRetryStrategy_1.AdaptiveRetryStrategy(maxAttempts); | ||
if (retryMode === util_retry_1.RETRY_MODES.ADAPTIVE) { | ||
return new util_retry_1.AdaptiveRetryStrategy(maxAttempts); | ||
} | ||
return new StandardRetryStrategy_1.StandardRetryStrategy(maxAttempts); | ||
return new util_retry_1.StandardRetryStrategy(maxAttempts); | ||
}, | ||
@@ -60,3 +59,3 @@ }; | ||
configFileSelector: (profile) => profile[exports.CONFIG_RETRY_MODE], | ||
default: config_1.DEFAULT_RETRY_MODE, | ||
default: util_retry_1.DEFAULT_RETRY_MODE, | ||
}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getDefaultRetryQuota = void 0; | ||
const constants_1 = require("./constants"); | ||
const util_retry_1 = require("@aws-sdk/util-retry"); | ||
const getDefaultRetryQuota = (initialRetryTokens, options) => { | ||
var _a, _b, _c; | ||
const MAX_CAPACITY = initialRetryTokens; | ||
const noRetryIncrement = (_a = options === null || options === void 0 ? void 0 : options.noRetryIncrement) !== null && _a !== void 0 ? _a : constants_1.NO_RETRY_INCREMENT; | ||
const retryCost = (_b = options === null || options === void 0 ? void 0 : options.retryCost) !== null && _b !== void 0 ? _b : constants_1.RETRY_COST; | ||
const timeoutRetryCost = (_c = options === null || options === void 0 ? void 0 : options.timeoutRetryCost) !== null && _c !== void 0 ? _c : constants_1.TIMEOUT_RETRY_COST; | ||
const noRetryIncrement = (_a = options === null || options === void 0 ? void 0 : options.noRetryIncrement) !== null && _a !== void 0 ? _a : util_retry_1.NO_RETRY_INCREMENT; | ||
const retryCost = (_b = options === null || options === void 0 ? void 0 : options.retryCost) !== null && _b !== void 0 ? _b : util_retry_1.RETRY_COST; | ||
const timeoutRetryCost = (_c = options === null || options === void 0 ? void 0 : options.timeoutRetryCost) !== null && _c !== void 0 ? _c : util_retry_1.TIMEOUT_RETRY_COST; | ||
let availableCapacity = initialRetryTokens; | ||
@@ -12,0 +12,0 @@ const getCapacityAmount = (error) => (error.name === "TimeoutError" ? timeoutRetryCost : retryCost); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.defaultDelayDecider = void 0; | ||
const constants_1 = require("./constants"); | ||
const defaultDelayDecider = (delayBase, attempts) => Math.floor(Math.min(constants_1.MAXIMUM_RETRY_DELAY, Math.random() * 2 ** attempts * delayBase)); | ||
const util_retry_1 = require("@aws-sdk/util-retry"); | ||
const defaultDelayDecider = (delayBase, attempts) => Math.floor(Math.min(util_retry_1.MAXIMUM_RETRY_DELAY, Math.random() * 2 ** attempts * delayBase)); | ||
exports.defaultDelayDecider = defaultDelayDecider; |
@@ -5,5 +5,3 @@ "use strict"; | ||
tslib_1.__exportStar(require("./AdaptiveRetryStrategy"), exports); | ||
tslib_1.__exportStar(require("./DefaultRateLimiter"), exports); | ||
tslib_1.__exportStar(require("./StandardRetryStrategy"), exports); | ||
tslib_1.__exportStar(require("./config"), exports); | ||
tslib_1.__exportStar(require("./configurations"), exports); | ||
@@ -14,2 +12,1 @@ tslib_1.__exportStar(require("./delayDecider"), exports); | ||
tslib_1.__exportStar(require("./retryMiddleware"), exports); | ||
tslib_1.__exportStar(require("./types"), exports); |
@@ -5,8 +5,8 @@ "use strict"; | ||
const protocol_http_1 = require("@aws-sdk/protocol-http"); | ||
const constants_1 = require("./constants"); | ||
const util_retry_1 = require("@aws-sdk/util-retry"); | ||
const omitRetryHeadersMiddleware = () => (next) => async (args) => { | ||
const { request } = args; | ||
if (protocol_http_1.HttpRequest.isInstance(request)) { | ||
delete request.headers[constants_1.INVOCATION_ID_HEADER]; | ||
delete request.headers[constants_1.REQUEST_HEADER]; | ||
delete request.headers[util_retry_1.INVOCATION_ID_HEADER]; | ||
delete request.headers[util_retry_1.REQUEST_HEADER]; | ||
} | ||
@@ -13,0 +13,0 @@ return next(args); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getRetryPlugin = exports.retryMiddlewareOptions = exports.retryMiddleware = void 0; | ||
exports.getRetryAfterHint = exports.getRetryPlugin = exports.retryMiddlewareOptions = exports.retryMiddleware = void 0; | ||
const protocol_http_1 = require("@aws-sdk/protocol-http"); | ||
const service_error_classification_1 = require("@aws-sdk/service-error-classification"); | ||
const util_retry_1 = require("@aws-sdk/util-retry"); | ||
const uuid_1 = require("uuid"); | ||
const util_1 = require("./util"); | ||
const retryMiddleware = (options) => (next, context) => async (args) => { | ||
const retryStrategy = await options.retryStrategy(); | ||
if (retryStrategy === null || retryStrategy === void 0 ? void 0 : retryStrategy.mode) | ||
context.userAgent = [...(context.userAgent || []), ["cfg/retry-mode", retryStrategy.mode]]; | ||
return retryStrategy.retry(next, args); | ||
let retryStrategy = await options.retryStrategy(); | ||
const maxAttempts = await options.maxAttempts(); | ||
if (isRetryStrategyV2(retryStrategy)) { | ||
retryStrategy = retryStrategy; | ||
let retryToken = await retryStrategy.acquireInitialRetryToken(context["partition_id"]); | ||
let lastError = new Error(); | ||
let attempts = 0; | ||
let totalRetryDelay = 0; | ||
const { request } = args; | ||
if (protocol_http_1.HttpRequest.isInstance(request)) { | ||
request.headers[util_retry_1.INVOCATION_ID_HEADER] = (0, uuid_1.v4)(); | ||
} | ||
while (true) { | ||
try { | ||
if (protocol_http_1.HttpRequest.isInstance(request)) { | ||
request.headers[util_retry_1.REQUEST_HEADER] = `attempt=${attempts + 1}; max=${maxAttempts}`; | ||
} | ||
const { response, output } = await next(args); | ||
retryStrategy.recordSuccess(retryToken); | ||
output.$metadata.attempts = attempts + 1; | ||
output.$metadata.totalRetryDelay = totalRetryDelay; | ||
return { response, output }; | ||
} | ||
catch (e) { | ||
const retryErrorInfo = getRetyErrorInto(e); | ||
lastError = (0, util_1.asSdkError)(e); | ||
try { | ||
retryToken = await retryStrategy.refreshRetryTokenForRetry(retryToken, retryErrorInfo); | ||
} | ||
catch (refreshError) { | ||
if (!lastError.$metadata) { | ||
lastError.$metadata = {}; | ||
} | ||
lastError.$metadata.attempts = attempts + 1; | ||
lastError.$metadata.totalRetryDelay = totalRetryDelay; | ||
throw lastError; | ||
} | ||
attempts = retryToken.getRetryCount(); | ||
const delay = retryToken.getRetryDelay(); | ||
totalRetryDelay += delay; | ||
await new Promise((resolve) => setTimeout(resolve, delay)); | ||
} | ||
} | ||
} | ||
else { | ||
retryStrategy = retryStrategy; | ||
if (retryStrategy === null || retryStrategy === void 0 ? void 0 : retryStrategy.mode) | ||
context.userAgent = [...(context.userAgent || []), ["cfg/retry-mode", retryStrategy.mode]]; | ||
return retryStrategy.retry(next, args); | ||
} | ||
}; | ||
exports.retryMiddleware = retryMiddleware; | ||
const isRetryStrategyV2 = (retryStrategy) => typeof retryStrategy.acquireInitialRetryToken !== "undefined" && | ||
typeof retryStrategy.refreshRetryTokenForRetry !== "undefined" && | ||
typeof retryStrategy.recordSuccess !== "undefined"; | ||
const getRetyErrorInto = (error) => { | ||
const errorInfo = { | ||
errorType: getRetryErrorType(error), | ||
}; | ||
const retryAfterHint = (0, exports.getRetryAfterHint)(error.$response); | ||
if (retryAfterHint) { | ||
errorInfo.retryAfterHint = retryAfterHint; | ||
} | ||
return errorInfo; | ||
}; | ||
const getRetryErrorType = (error) => { | ||
if ((0, service_error_classification_1.isThrottlingError)(error)) | ||
return "THROTTLING"; | ||
if ((0, service_error_classification_1.isTransientError)(error)) | ||
return "TRANSIENT"; | ||
if ((0, service_error_classification_1.isServerError)(error)) | ||
return "SERVER_ERROR"; | ||
return "CLIENT_ERROR"; | ||
}; | ||
exports.retryMiddlewareOptions = { | ||
@@ -24,1 +97,15 @@ name: "retryMiddleware", | ||
exports.getRetryPlugin = getRetryPlugin; | ||
const getRetryAfterHint = (response) => { | ||
if (!protocol_http_1.HttpResponse.isInstance(response)) | ||
return; | ||
const retryAfterHeaderName = Object.keys(response.headers).find((key) => key.toLowerCase() === "retry-after"); | ||
if (!retryAfterHeaderName) | ||
return; | ||
const retryAfter = response.headers[retryAfterHeaderName]; | ||
const retryAfterSeconds = Number(retryAfter); | ||
if (!Number.isNaN(retryAfterSeconds)) | ||
return new Date(retryAfterSeconds * 1000); | ||
const retryAfterDate = new Date(retryAfter); | ||
return retryAfterDate; | ||
}; | ||
exports.getRetryAfterHint = getRetryAfterHint; |
@@ -6,8 +6,8 @@ "use strict"; | ||
const service_error_classification_1 = require("@aws-sdk/service-error-classification"); | ||
const util_retry_1 = require("@aws-sdk/util-retry"); | ||
const uuid_1 = require("uuid"); | ||
const config_1 = require("./config"); | ||
const constants_1 = require("./constants"); | ||
const defaultRetryQuota_1 = require("./defaultRetryQuota"); | ||
const delayDecider_1 = require("./delayDecider"); | ||
const retryDecider_1 = require("./retryDecider"); | ||
const util_1 = require("./util"); | ||
class StandardRetryStrategy { | ||
@@ -17,6 +17,6 @@ constructor(maxAttemptsProvider, options) { | ||
this.maxAttemptsProvider = maxAttemptsProvider; | ||
this.mode = config_1.RETRY_MODES.STANDARD; | ||
this.mode = util_retry_1.RETRY_MODES.STANDARD; | ||
this.retryDecider = (_a = options === null || options === void 0 ? void 0 : options.retryDecider) !== null && _a !== void 0 ? _a : retryDecider_1.defaultRetryDecider; | ||
this.delayDecider = (_b = options === null || options === void 0 ? void 0 : options.delayDecider) !== null && _b !== void 0 ? _b : delayDecider_1.defaultDelayDecider; | ||
this.retryQuota = (_c = options === null || options === void 0 ? void 0 : options.retryQuota) !== null && _c !== void 0 ? _c : (0, defaultRetryQuota_1.getDefaultRetryQuota)(constants_1.INITIAL_RETRY_TOKENS); | ||
this.retryQuota = (_c = options === null || options === void 0 ? void 0 : options.retryQuota) !== null && _c !== void 0 ? _c : (0, defaultRetryQuota_1.getDefaultRetryQuota)(util_retry_1.INITIAL_RETRY_TOKENS); | ||
} | ||
@@ -32,3 +32,3 @@ shouldRetry(error, attempts, maxAttempts) { | ||
catch (error) { | ||
maxAttempts = config_1.DEFAULT_MAX_ATTEMPTS; | ||
maxAttempts = util_retry_1.DEFAULT_MAX_ATTEMPTS; | ||
} | ||
@@ -44,3 +44,3 @@ return maxAttempts; | ||
if (protocol_http_1.HttpRequest.isInstance(request)) { | ||
request.headers[constants_1.INVOCATION_ID_HEADER] = (0, uuid_1.v4)(); | ||
request.headers[util_retry_1.INVOCATION_ID_HEADER] = (0, uuid_1.v4)(); | ||
} | ||
@@ -50,3 +50,3 @@ while (true) { | ||
if (protocol_http_1.HttpRequest.isInstance(request)) { | ||
request.headers[constants_1.REQUEST_HEADER] = `attempt=${attempts + 1}; max=${maxAttempts}`; | ||
request.headers[util_retry_1.REQUEST_HEADER] = `attempt=${attempts + 1}; max=${maxAttempts}`; | ||
} | ||
@@ -66,7 +66,7 @@ if (options === null || options === void 0 ? void 0 : options.beforeRequest) { | ||
catch (e) { | ||
const err = asSdkError(e); | ||
const err = (0, util_1.asSdkError)(e); | ||
attempts++; | ||
if (this.shouldRetry(err, attempts, maxAttempts)) { | ||
retryTokenAmount = this.retryQuota.retrieveRetryTokens(err); | ||
const delayFromDecider = this.delayDecider((0, service_error_classification_1.isThrottlingError)(err) ? constants_1.THROTTLING_RETRY_DELAY_BASE : constants_1.DEFAULT_RETRY_DELAY_BASE, attempts); | ||
const delayFromDecider = this.delayDecider((0, service_error_classification_1.isThrottlingError)(err) ? util_retry_1.THROTTLING_RETRY_DELAY_BASE : util_retry_1.DEFAULT_RETRY_DELAY_BASE, attempts); | ||
const delayFromResponse = getDelayFromRetryAfterHeader(err.$response); | ||
@@ -102,10 +102,1 @@ const delay = Math.max(delayFromResponse || 0, delayFromDecider); | ||
}; | ||
const asSdkError = (error) => { | ||
if (error instanceof Error) | ||
return error; | ||
if (error instanceof Object) | ||
return Object.assign(new Error(), error); | ||
if (typeof error === "string") | ||
return new Error(error); | ||
return new Error(`AWS SDK error wrapper for ${error}`); | ||
}; |
@@ -1,3 +0,2 @@ | ||
import { RETRY_MODES } from "./config"; | ||
import { DefaultRateLimiter } from "./DefaultRateLimiter"; | ||
import { DefaultRateLimiter, RETRY_MODES } from "@aws-sdk/util-retry"; | ||
import { StandardRetryStrategy } from "./StandardRetryStrategy"; | ||
@@ -4,0 +3,0 @@ export class AdaptiveRetryStrategy extends StandardRetryStrategy { |
import { normalizeProvider } from "@aws-sdk/util-middleware"; | ||
import { AdaptiveRetryStrategy } from "./AdaptiveRetryStrategy"; | ||
import { DEFAULT_MAX_ATTEMPTS, DEFAULT_RETRY_MODE, RETRY_MODES } from "./config"; | ||
import { StandardRetryStrategy } from "./StandardRetryStrategy"; | ||
import { AdaptiveRetryStrategy, DEFAULT_MAX_ATTEMPTS, DEFAULT_RETRY_MODE, RETRY_MODES, StandardRetryStrategy, } from "@aws-sdk/util-retry"; | ||
export const ENV_MAX_ATTEMPTS = "AWS_MAX_ATTEMPTS"; | ||
@@ -31,2 +29,3 @@ export const CONFIG_MAX_ATTEMPTS = "max_attempts"; | ||
export const resolveRetryConfig = (input) => { | ||
const { retryStrategy } = input; | ||
const maxAttempts = normalizeProvider(input.maxAttempts ?? DEFAULT_MAX_ATTEMPTS); | ||
@@ -37,4 +36,4 @@ return { | ||
retryStrategy: async () => { | ||
if (input.retryStrategy) { | ||
return input.retryStrategy; | ||
if (retryStrategy) { | ||
return retryStrategy; | ||
} | ||
@@ -41,0 +40,0 @@ const retryMode = await normalizeProvider(input.retryMode)(); |
@@ -1,2 +0,2 @@ | ||
import { NO_RETRY_INCREMENT, RETRY_COST, TIMEOUT_RETRY_COST } from "./constants"; | ||
import { NO_RETRY_INCREMENT, RETRY_COST, TIMEOUT_RETRY_COST } from "@aws-sdk/util-retry"; | ||
export const getDefaultRetryQuota = (initialRetryTokens, options) => { | ||
@@ -3,0 +3,0 @@ const MAX_CAPACITY = initialRetryTokens; |
@@ -1,2 +0,2 @@ | ||
import { MAXIMUM_RETRY_DELAY } from "./constants"; | ||
import { MAXIMUM_RETRY_DELAY } from "@aws-sdk/util-retry"; | ||
export const defaultDelayDecider = (delayBase, attempts) => Math.floor(Math.min(MAXIMUM_RETRY_DELAY, Math.random() * 2 ** attempts * delayBase)); |
export * from "./AdaptiveRetryStrategy"; | ||
export * from "./DefaultRateLimiter"; | ||
export * from "./StandardRetryStrategy"; | ||
export * from "./config"; | ||
export * from "./configurations"; | ||
@@ -10,2 +8,1 @@ export * from "./delayDecider"; | ||
export * from "./retryMiddleware"; | ||
export * from "./types"; |
import { HttpRequest } from "@aws-sdk/protocol-http"; | ||
import { INVOCATION_ID_HEADER, REQUEST_HEADER } from "./constants"; | ||
import { INVOCATION_ID_HEADER, REQUEST_HEADER } from "@aws-sdk/util-retry"; | ||
export const omitRetryHeadersMiddleware = () => (next) => async (args) => { | ||
@@ -4,0 +4,0 @@ const { request } = args; |
@@ -0,7 +1,80 @@ | ||
import { HttpRequest, HttpResponse } from "@aws-sdk/protocol-http"; | ||
import { isServerError, isThrottlingError, isTransientError } from "@aws-sdk/service-error-classification"; | ||
import { INVOCATION_ID_HEADER, REQUEST_HEADER } from "@aws-sdk/util-retry"; | ||
import { v4 } from "uuid"; | ||
import { asSdkError } from "./util"; | ||
export const retryMiddleware = (options) => (next, context) => async (args) => { | ||
const retryStrategy = await options.retryStrategy(); | ||
if (retryStrategy?.mode) | ||
context.userAgent = [...(context.userAgent || []), ["cfg/retry-mode", retryStrategy.mode]]; | ||
return retryStrategy.retry(next, args); | ||
let retryStrategy = await options.retryStrategy(); | ||
const maxAttempts = await options.maxAttempts(); | ||
if (isRetryStrategyV2(retryStrategy)) { | ||
retryStrategy = retryStrategy; | ||
let retryToken = await retryStrategy.acquireInitialRetryToken(context["partition_id"]); | ||
let lastError = new Error(); | ||
let attempts = 0; | ||
let totalRetryDelay = 0; | ||
const { request } = args; | ||
if (HttpRequest.isInstance(request)) { | ||
request.headers[INVOCATION_ID_HEADER] = v4(); | ||
} | ||
while (true) { | ||
try { | ||
if (HttpRequest.isInstance(request)) { | ||
request.headers[REQUEST_HEADER] = `attempt=${attempts + 1}; max=${maxAttempts}`; | ||
} | ||
const { response, output } = await next(args); | ||
retryStrategy.recordSuccess(retryToken); | ||
output.$metadata.attempts = attempts + 1; | ||
output.$metadata.totalRetryDelay = totalRetryDelay; | ||
return { response, output }; | ||
} | ||
catch (e) { | ||
const retryErrorInfo = getRetyErrorInto(e); | ||
lastError = asSdkError(e); | ||
try { | ||
retryToken = await retryStrategy.refreshRetryTokenForRetry(retryToken, retryErrorInfo); | ||
} | ||
catch (refreshError) { | ||
if (!lastError.$metadata) { | ||
lastError.$metadata = {}; | ||
} | ||
lastError.$metadata.attempts = attempts + 1; | ||
lastError.$metadata.totalRetryDelay = totalRetryDelay; | ||
throw lastError; | ||
} | ||
attempts = retryToken.getRetryCount(); | ||
const delay = retryToken.getRetryDelay(); | ||
totalRetryDelay += delay; | ||
await new Promise((resolve) => setTimeout(resolve, delay)); | ||
} | ||
} | ||
} | ||
else { | ||
retryStrategy = retryStrategy; | ||
if (retryStrategy?.mode) | ||
context.userAgent = [...(context.userAgent || []), ["cfg/retry-mode", retryStrategy.mode]]; | ||
return retryStrategy.retry(next, args); | ||
} | ||
}; | ||
const isRetryStrategyV2 = (retryStrategy) => typeof retryStrategy.acquireInitialRetryToken !== "undefined" && | ||
typeof retryStrategy.refreshRetryTokenForRetry !== "undefined" && | ||
typeof retryStrategy.recordSuccess !== "undefined"; | ||
const getRetyErrorInto = (error) => { | ||
const errorInfo = { | ||
errorType: getRetryErrorType(error), | ||
}; | ||
const retryAfterHint = getRetryAfterHint(error.$response); | ||
if (retryAfterHint) { | ||
errorInfo.retryAfterHint = retryAfterHint; | ||
} | ||
return errorInfo; | ||
}; | ||
const getRetryErrorType = (error) => { | ||
if (isThrottlingError(error)) | ||
return "THROTTLING"; | ||
if (isTransientError(error)) | ||
return "TRANSIENT"; | ||
if (isServerError(error)) | ||
return "SERVER_ERROR"; | ||
return "CLIENT_ERROR"; | ||
}; | ||
export const retryMiddlewareOptions = { | ||
@@ -19,1 +92,14 @@ name: "retryMiddleware", | ||
}); | ||
export const getRetryAfterHint = (response) => { | ||
if (!HttpResponse.isInstance(response)) | ||
return; | ||
const retryAfterHeaderName = Object.keys(response.headers).find((key) => key.toLowerCase() === "retry-after"); | ||
if (!retryAfterHeaderName) | ||
return; | ||
const retryAfter = response.headers[retryAfterHeaderName]; | ||
const retryAfterSeconds = Number(retryAfter); | ||
if (!Number.isNaN(retryAfterSeconds)) | ||
return new Date(retryAfterSeconds * 1000); | ||
const retryAfterDate = new Date(retryAfter); | ||
return retryAfterDate; | ||
}; |
import { HttpRequest, HttpResponse } from "@aws-sdk/protocol-http"; | ||
import { isThrottlingError } from "@aws-sdk/service-error-classification"; | ||
import { DEFAULT_MAX_ATTEMPTS, DEFAULT_RETRY_DELAY_BASE, INITIAL_RETRY_TOKENS, INVOCATION_ID_HEADER, REQUEST_HEADER, RETRY_MODES, THROTTLING_RETRY_DELAY_BASE, } from "@aws-sdk/util-retry"; | ||
import { v4 } from "uuid"; | ||
import { DEFAULT_MAX_ATTEMPTS, RETRY_MODES } from "./config"; | ||
import { DEFAULT_RETRY_DELAY_BASE, INITIAL_RETRY_TOKENS, INVOCATION_ID_HEADER, REQUEST_HEADER, THROTTLING_RETRY_DELAY_BASE, } from "./constants"; | ||
import { getDefaultRetryQuota } from "./defaultRetryQuota"; | ||
import { defaultDelayDecider } from "./delayDecider"; | ||
import { defaultRetryDecider } from "./retryDecider"; | ||
import { asSdkError } from "./util"; | ||
export class StandardRetryStrategy { | ||
@@ -91,10 +91,1 @@ constructor(maxAttemptsProvider, options) { | ||
}; | ||
const asSdkError = (error) => { | ||
if (error instanceof Error) | ||
return error; | ||
if (error instanceof Object) | ||
return Object.assign(new Error(), error); | ||
if (typeof error === "string") | ||
return new Error(error); | ||
return new Error(`AWS SDK error wrapper for ${error}`); | ||
}; |
import { FinalizeHandler, FinalizeHandlerArguments, MetadataBearer, Provider } from "@aws-sdk/types"; | ||
import { RateLimiter } from "@aws-sdk/util-retry"; | ||
import { StandardRetryStrategy, StandardRetryStrategyOptions } from "./StandardRetryStrategy"; | ||
import { RateLimiter } from "./types"; | ||
/** | ||
@@ -10,2 +10,5 @@ * Strategy options to be passed to AdaptiveRetryStrategy | ||
} | ||
/** | ||
* @deprected use AdaptiveRetryStrategy from @aws-sdk/util-retry | ||
*/ | ||
export declare class AdaptiveRetryStrategy extends StandardRetryStrategy { | ||
@@ -12,0 +15,0 @@ private rateLimiter; |
import { LoadedConfigSelectors } from "@aws-sdk/node-config-provider"; | ||
import { Provider, RetryStrategy } from "@aws-sdk/types"; | ||
import { Provider, RetryStrategy, RetryStrategyV2 } from "@aws-sdk/types"; | ||
export declare const ENV_MAX_ATTEMPTS = "AWS_MAX_ATTEMPTS"; | ||
@@ -14,3 +14,3 @@ export declare const CONFIG_MAX_ATTEMPTS = "max_attempts"; | ||
*/ | ||
retryStrategy?: RetryStrategy; | ||
retryStrategy?: RetryStrategy | RetryStrategyV2; | ||
} | ||
@@ -32,3 +32,3 @@ interface PreviouslyResolved { | ||
*/ | ||
retryStrategy: Provider<RetryStrategy>; | ||
retryStrategy: Provider<RetryStrategyV2 | RetryStrategy>; | ||
} | ||
@@ -35,0 +35,0 @@ export declare const resolveRetryConfig: <T>(input: T & PreviouslyResolved & RetryInputConfig) => T & RetryResolvedConfig; |
export * from "./AdaptiveRetryStrategy"; | ||
export * from "./DefaultRateLimiter"; | ||
export * from "./StandardRetryStrategy"; | ||
export * from "./config"; | ||
export * from "./configurations"; | ||
@@ -10,2 +8,1 @@ export * from "./delayDecider"; | ||
export * from "./retryMiddleware"; | ||
export * from "./types"; |
@@ -6,1 +6,2 @@ import { AbsoluteLocation, FinalizeHandler, FinalizeRequestHandlerOptions, HandlerExecutionContext, MetadataBearer, Pluggable } from "@aws-sdk/types"; | ||
export declare const getRetryPlugin: (options: RetryResolvedConfig) => Pluggable<any, any>; | ||
export declare const getRetryAfterHint: (response: unknown) => Date | undefined; |
@@ -11,2 +11,5 @@ import { FinalizeHandler, FinalizeHandlerArguments, MetadataBearer, Provider, RetryStrategy } from "@aws-sdk/types"; | ||
} | ||
/** | ||
* @deprected use StandardRetryStrategy from @aws-sdk/util-retry | ||
*/ | ||
export declare class StandardRetryStrategy implements RetryStrategy { | ||
@@ -13,0 +16,0 @@ private readonly maxAttemptsProvider; |
@@ -7,2 +7,3 @@ import { | ||
} from "@aws-sdk/types"; | ||
import { RateLimiter } from "@aws-sdk/util-retry"; | ||
import { | ||
@@ -12,3 +13,2 @@ StandardRetryStrategy, | ||
} from "./StandardRetryStrategy"; | ||
import { RateLimiter } from "./types"; | ||
export interface AdaptiveRetryStrategyOptions | ||
@@ -15,0 +15,0 @@ extends StandardRetryStrategyOptions { |
import { LoadedConfigSelectors } from "@aws-sdk/node-config-provider"; | ||
import { Provider, RetryStrategy } from "@aws-sdk/types"; | ||
import { Provider, RetryStrategy, RetryStrategyV2 } from "@aws-sdk/types"; | ||
export declare const ENV_MAX_ATTEMPTS = "AWS_MAX_ATTEMPTS"; | ||
@@ -8,3 +8,3 @@ export declare const CONFIG_MAX_ATTEMPTS = "max_attempts"; | ||
maxAttempts?: number | Provider<number>; | ||
retryStrategy?: RetryStrategy; | ||
retryStrategy?: RetryStrategy | RetryStrategyV2; | ||
} | ||
@@ -16,3 +16,3 @@ interface PreviouslyResolved { | ||
maxAttempts: Provider<number>; | ||
retryStrategy: Provider<RetryStrategy>; | ||
retryStrategy: Provider<RetryStrategyV2 | RetryStrategy>; | ||
} | ||
@@ -19,0 +19,0 @@ export declare const resolveRetryConfig: <T>( |
export * from "./AdaptiveRetryStrategy"; | ||
export * from "./DefaultRateLimiter"; | ||
export * from "./StandardRetryStrategy"; | ||
export * from "./config"; | ||
export * from "./configurations"; | ||
@@ -10,2 +8,1 @@ export * from "./delayDecider"; | ||
export * from "./retryMiddleware"; | ||
export * from "./types"; |
@@ -21,1 +21,2 @@ import { | ||
) => Pluggable<any, any>; | ||
export declare const getRetryAfterHint: (response: unknown) => Date | undefined; |
{ | ||
"name": "@aws-sdk/middleware-retry", | ||
"version": "3.226.0", | ||
"version": "3.229.0", | ||
"scripts": { | ||
@@ -24,3 +24,3 @@ "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'", | ||
"@aws-sdk/protocol-http": "3.226.0", | ||
"@aws-sdk/service-error-classification": "3.226.0", | ||
"@aws-sdk/service-error-classification": "3.229.0", | ||
"@aws-sdk/types": "3.226.0", | ||
@@ -27,0 +27,0 @@ "@aws-sdk/util-middleware": "3.226.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
59513
47
1077
+ Added@aws-sdk/service-error-classification@3.229.0(transitive)
- Removed@aws-sdk/service-error-classification@3.226.0(transitive)