Skip to content

Commit

Permalink
fix: add loggerMiddleware in build step (#1520)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr authored Sep 14, 2020
1 parent 96ee3af commit fece417
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
10 changes: 5 additions & 5 deletions packages/middleware-logger/src/loggerMiddleware.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FinalizeHandlerArguments, Logger, MiddlewareStack } from "@aws-sdk/types";
import { BuildHandlerArguments, Logger, MiddlewareStack } from "@aws-sdk/types";

import { getLoggerPlugin, loggerMiddleware, loggerMiddlewareOptions } from "./loggerMiddleware";

Expand Down Expand Up @@ -54,14 +54,14 @@ describe("loggerMiddleware", () => {
});

it("returns without logging if context.logger is not defined", async () => {
const response = await loggerMiddleware()(next, {})(args as FinalizeHandlerArguments<any>);
const response = await loggerMiddleware()(next, {})(args as BuildHandlerArguments<any>);
expect(next).toHaveBeenCalledTimes(1);
expect(response).toStrictEqual(mockResponse);
});

it("returns without logging if context.logger doesn't have debug/info functions", async () => {
const logger = {} as Logger;
const response = await loggerMiddleware()(next, { logger })(args as FinalizeHandlerArguments<any>);
const response = await loggerMiddleware()(next, { logger })(args as BuildHandlerArguments<any>);
expect(next).toHaveBeenCalledTimes(1);
expect(response).toStrictEqual(mockResponse);
});
Expand All @@ -77,7 +77,7 @@ describe("loggerMiddleware", () => {
outputFilterSensitiveLog,
};

const response = await loggerMiddleware()(next, context)(args as FinalizeHandlerArguments<any>);
const response = await loggerMiddleware()(next, context)(args as BuildHandlerArguments<any>);
expect(next).toHaveBeenCalledTimes(1);
expect(response).toStrictEqual(mockResponse);

Expand All @@ -97,7 +97,7 @@ describe("loggerMiddleware", () => {

it("logs httpRequest, httpResponse if context.logger has debug function", async () => {
const logger = ({ debug: jest.fn() } as unknown) as Logger;
const response = await loggerMiddleware()(next, { logger })(args as FinalizeHandlerArguments<any>);
const response = await loggerMiddleware()(next, { logger })(args as BuildHandlerArguments<any>);
expect(next).toHaveBeenCalledTimes(1);
expect(response).toStrictEqual(mockResponse);

Expand Down
18 changes: 8 additions & 10 deletions packages/middleware-logger/src/loggerMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import {
AbsoluteLocation,
FinalizeHandler,
FinalizeHandlerArguments,
FinalizeHandlerOutput,
FinalizeRequestHandlerOptions,
BuildHandler,
BuildHandlerArguments,
BuildHandlerOptions,
BuildHandlerOutput,
HandlerExecutionContext,
MetadataBearer,
Pluggable,
} from "@aws-sdk/types";

export const loggerMiddleware = () => <Output extends MetadataBearer = MetadataBearer>(
next: FinalizeHandler<any, Output>,
next: BuildHandler<any, Output>,
context: HandlerExecutionContext
): FinalizeHandler<any, Output> => async (
args: FinalizeHandlerArguments<any>
): Promise<FinalizeHandlerOutput<Output>> => {
): BuildHandler<any, Output> => async (args: BuildHandlerArguments<any>): Promise<BuildHandlerOutput<Output>> => {
const { logger, inputFilterSensitiveLog, outputFilterSensitiveLog } = context;

const response = await next(args);
Expand Down Expand Up @@ -47,10 +45,10 @@ export const loggerMiddleware = () => <Output extends MetadataBearer = MetadataB
return response;
};

export const loggerMiddlewareOptions: FinalizeRequestHandlerOptions & AbsoluteLocation = {
export const loggerMiddlewareOptions: BuildHandlerOptions & AbsoluteLocation = {
name: "loggerMiddleware",
tags: ["LOGGER"],
step: "finalizeRequest",
step: "build",
};

// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down

0 comments on commit fece417

Please sign in to comment.