diff --git a/.changeset/rotten-islands-brake.md b/.changeset/rotten-islands-brake.md new file mode 100644 index 00000000000..62e3735012d --- /dev/null +++ b/.changeset/rotten-islands-brake.md @@ -0,0 +1,6 @@ +--- +"@smithy/types": patch +"@smithy/core": patch +--- + +Add internal error and success handlers to `HttpSigner`. diff --git a/packages/core/src/middleware-http-signing/httpSigningMiddleware.ts b/packages/core/src/middleware-http-signing/httpSigningMiddleware.ts index 70ffa129d34..c77fc96acc0 100644 --- a/packages/core/src/middleware-http-signing/httpSigningMiddleware.ts +++ b/packages/core/src/middleware-http-signing/httpSigningMiddleware.ts @@ -1,5 +1,6 @@ import { HttpRequest } from "@smithy/protocol-http"; import { + ErrorHandler, FinalizeHandler, FinalizeHandlerArguments, FinalizeHandlerOutput, @@ -7,6 +8,7 @@ import { HandlerExecutionContext, SelectedHttpAuthScheme, SMITHY_CONTEXT_KEY, + SuccessHandler, } from "@smithy/types"; import { getSmithyContext } from "@smithy/util-middleware"; @@ -24,6 +26,15 @@ interface HttpSigningMiddlewareHandlerExecutionContext extends HandlerExecutionC [SMITHY_CONTEXT_KEY]?: HttpSigningMiddlewareSmithyContext; } +const defaultErrorHandler: ErrorHandler = (signingProperties) => (error) => { + throw error; +}; + +const defaultSuccessHandler: SuccessHandler = ( + httpResponse: unknown, + signingProperties: Record +): void => {}; + /** * @internal */ @@ -45,12 +56,14 @@ export const httpSigningMiddleware = ): (error: E) => never; +} + +/** + * @internal + */ +export interface SuccessHandler { + (httpResponse: HttpResponse | unknown, signingProperties: Record): void; +} + /** * Interface to sign identity and signing properties. * @internal @@ -14,4 +28,17 @@ export interface HttpSigner { * @returns signed request in a promise */ sign(httpRequest: HttpRequest, identity: Identity, signingProperties: Record): Promise; + /** + * Handler that executes after the {@link HttpSigner.sign} invocation and corresponding + * middleware throws an error. + * The error handler is expected to throw the error it receives, so the return type of the error handler is `never`. + * @internal + */ + errorHandler?: ErrorHandler; + /** + * Handler that executes after the {@link HttpSigner.sign} invocation and corresponding + * middleware succeeds. + * @internal + */ + successHandler?: SuccessHandler; }