diff --git a/packages/middleware-retry/src/configurations.ts b/packages/middleware-retry/src/configurations.ts index 6dfceea2aa5..1b6fb7f01cd 100644 --- a/packages/middleware-retry/src/configurations.ts +++ b/packages/middleware-retry/src/configurations.ts @@ -57,8 +57,6 @@ export interface PreviouslyResolved { * @internal */ retryMode: string | Provider; - - systemClockOffset?: number; } /** diff --git a/packages/middleware-retry/src/retryDecider.ts b/packages/middleware-retry/src/retryDecider.ts index 5a43f9f34af..e2913d065bc 100644 --- a/packages/middleware-retry/src/retryDecider.ts +++ b/packages/middleware-retry/src/retryDecider.ts @@ -6,6 +6,9 @@ import { } from "@smithy/service-error-classification"; import { SdkError } from "@smithy/types"; +/** + * @deprecated this is only used in the deprecated StandardRetryStrategy. Do not use in new code. + */ export const defaultRetryDecider = (error: SdkError) => { if (!error) { return false; diff --git a/packages/middleware-retry/src/retryMiddleware.ts b/packages/middleware-retry/src/retryMiddleware.ts index da7a9a47ced..4424cca1726 100644 --- a/packages/middleware-retry/src/retryMiddleware.ts +++ b/packages/middleware-retry/src/retryMiddleware.ts @@ -16,18 +16,15 @@ import { RetryStrategyV2, RetryToken, SdkError, - SkdErrorWithClockSkewMetadata, } from "@smithy/types"; import { INVOCATION_ID_HEADER, REQUEST_HEADER } from "@smithy/util-retry"; import { v4 } from "uuid"; -import { PreviouslyResolved, RetryResolvedConfig } from "./configurations"; +import { RetryResolvedConfig } from "./configurations"; import { isStreamingPayload } from "./isStreamingPayload/isStreamingPayload"; import { asSdkError } from "./util"; -export const retryMiddleware = (options: RetryResolvedConfig & Partial) => < - Output extends MetadataBearer = MetadataBearer ->( +export const retryMiddleware = (options: RetryResolvedConfig) => ( next: FinalizeHandler, context: HandlerExecutionContext ): FinalizeHandler => async ( @@ -49,30 +46,19 @@ export const retryMiddleware = (options: RetryResolvedConfig & Partial typeof (retryStrategy as RetryStrategyV2).refreshRetryTokenForRetry !== "undefined" && typeof (retryStrategy as RetryStrategyV2).recordSuccess !== "undefined"; -const getRetryErrorInfo = (error: SkdErrorWithClockSkewMetadata): RetryErrorInfo => { +const getRetryErrorInfo = (error: SdkError): RetryErrorInfo => { const errorInfo: RetryErrorInfo = { error, errorType: getRetryErrorType(error), @@ -122,7 +108,7 @@ const getRetryErrorInfo = (error: SkdErrorWithClockSkewMetadata): RetryErrorInfo return errorInfo; }; -const getRetryErrorType = (error: SkdErrorWithClockSkewMetadata): RetryErrorType => { +const getRetryErrorType = (error: SdkError): RetryErrorType => { if (isThrottlingError(error)) return "THROTTLING"; if (isTransientError(error)) return "TRANSIENT"; if (isServerError(error)) return "SERVER_ERROR"; diff --git a/packages/service-error-classification/src/index.ts b/packages/service-error-classification/src/index.ts index c3e6be11d19..77941ba8a5d 100644 --- a/packages/service-error-classification/src/index.ts +++ b/packages/service-error-classification/src/index.ts @@ -1,4 +1,4 @@ -import { SdkError, SkdErrorWithClockSkewMetadata } from "@smithy/types"; +import { SdkError } from "@smithy/types"; import { CLOCK_SKEW_ERROR_CODES, @@ -10,8 +10,16 @@ import { export const isRetryableByTrait = (error: SdkError) => error.$retryable !== undefined; +/** + * @deprecated use isClockSkewCorrectedError. This is only used in deprecated code. + */ export const isClockSkewError = (error: SdkError) => CLOCK_SKEW_ERROR_CODES.includes(error.name); +/** + * @returns whether the error resulted in a systemClockOffset aka clock skew correction. + */ +export const isClockSkewCorrectedError = (error: SdkError) => error.$metadata?.clockSkewCorrected; + export const isThrottlingError = (error: SdkError) => error.$metadata?.httpStatusCode === 429 || THROTTLING_ERROR_CODES.includes(error.name) || @@ -23,8 +31,8 @@ export const isThrottlingError = (error: SdkError) => * cause where the NodeHttpHandler does not decorate the Error with * the name "TimeoutError" to be checked by the TRANSIENT_ERROR_CODES condition. */ -export const isTransientError = (error: SdkError | SkdErrorWithClockSkewMetadata) => - (error as SkdErrorWithClockSkewMetadata).$metadata?.clockSkewCorrected || +export const isTransientError = (error: SdkError) => + isClockSkewCorrectedError(error) || TRANSIENT_ERROR_CODES.includes(error.name) || NODEJS_TIMEOUT_ERROR_CODES.includes((error as { code?: string })?.code || "") || TRANSIENT_ERROR_STATUS_CODES.includes(error.$metadata?.httpStatusCode || 0); diff --git a/packages/types/src/shapes.ts b/packages/types/src/shapes.ts index e3f3af26be9..129444877c1 100644 --- a/packages/types/src/shapes.ts +++ b/packages/types/src/shapes.ts @@ -79,15 +79,15 @@ export interface SmithyException { * the base exception for the service should be used. Each client exports * a base ServiceException prefixed with the service name. */ -export type SdkError = Error & Partial & Partial; - -/** - * @internal - * - * @deprecated for same reason as SdkError. Use public client modeled exceptions in application code. - */ -export type SkdErrorWithClockSkewMetadata = SdkError & { - $metadata: SdkError["$metadata"] & { - clockSkewCorrected?: boolean; +export type SdkError = Error & + Partial & + Partial & { + $metadata?: Partial["$metadata"] & { + /** + * If present, will have value of true and indicates that the error resulted in a + * correction of the clock skew, a.k.a. config.systemClockOffset. + * This is specific to AWS SDK and sigv4. + */ + readonly clockSkewCorrected?: true; + }; }; -};