Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
next: FinalizeHandler,
args: FinalizeHandlerArguments<input>
) {
let retries = 0;
let totalDelay = 0;
while (true) {
try {
const { response, output } = await next(args);
output.$metadata.retries = retries;
output.$metadata.totalRetryDelay = totalDelay;
return { response, output };
} catch (err) {
if (this.shouldRetry(err as SdkError, retries)) {
const delay = this.delayDecider(
isThrottlingError(err)
? THROTTLING_RETRY_DELAY_BASE
: DEFAULT_RETRY_DELAY_BASE,
retries++
);
totalDelay += delay;
await new Promise(resolve => setTimeout(resolve, delay));
continue;
}
if (!err.$metadata) {
err.$metadata = {};
}
err.$metadata.retries = retries;
err.$metadata.totalRetryDelay = totalDelay;
if (error.connectionError) {
return true;
}
if (
hasMetadata(error) &&
error.$metadata.httpStatusCode &&
RETRYABLE_STATUS_CODES.has(error.$metadata.httpStatusCode)
) {
return true;
}
return (
isStillProcessingError(error) ||
isThrottlingError(error) ||
isClockSkewError(error)
);
};