Skip to content

Commit 5a001ee

Browse files
committed
chore: move logging of output/response to serde
1 parent 231723b commit 5a001ee

File tree

2 files changed

+36
-21
lines changed

2 files changed

+36
-21
lines changed

packages/middleware-logger/src/loggerMiddleware.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const loggerMiddleware = () => <Output extends MetadataBearer = MetadataB
1313
next: BuildHandler<any, Output>,
1414
context: HandlerExecutionContext
1515
): BuildHandler<any, Output> => async (args: BuildHandlerArguments<any>): Promise<BuildHandlerOutput<Output>> => {
16-
const { logger, inputFilterSensitiveLog, outputFilterSensitiveLog } = context;
16+
const { logger } = context;
1717

1818
const response = await next(args);
1919

@@ -22,19 +22,13 @@ export const loggerMiddleware = () => <Output extends MetadataBearer = MetadataB
2222
}
2323

2424
const {
25-
output: { $metadata, ...outputWithoutMetadata },
25+
output: { $metadata },
2626
} = response;
2727

28-
if (typeof logger.debug === "function") {
29-
logger.debug({
30-
httpResponse: response.response,
31-
});
32-
}
33-
28+
// Suggested custom metadata in https://github.com/aws/aws-sdk-js-v3/issues/1491#issuecomment-692174256
3429
if (typeof logger.info === "function") {
3530
logger.info({
3631
$metadata,
37-
output: outputFilterSensitiveLog(outputWithoutMetadata),
3832
});
3933
}
4034

packages/middleware-serde/src/deserializerMiddleware.ts

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,42 @@ import {
33
DeserializeHandlerArguments,
44
DeserializeHandlerOutput,
55
DeserializeMiddleware,
6+
HandlerExecutionContext,
67
ResponseDeserializer,
78
} from "@aws-sdk/types";
89

9-
export function deserializerMiddleware<Input extends object, Output extends object, RuntimeUtils = any>(
10+
export const deserializerMiddleware = <Input extends object, Output extends object, RuntimeUtils = any>(
1011
options: RuntimeUtils,
1112
deserializer: ResponseDeserializer<any, any, RuntimeUtils>
12-
): DeserializeMiddleware<Input, Output> {
13-
return (next: DeserializeHandler<Input, Output>): DeserializeHandler<Input, Output> => async (
14-
args: DeserializeHandlerArguments<Input>
15-
): Promise<DeserializeHandlerOutput<Output>> => {
16-
const { response } = await next(args);
17-
const parsed = await deserializer(response, options);
18-
return {
19-
response,
20-
output: parsed as Output,
21-
};
13+
): DeserializeMiddleware<Input, Output> => (
14+
next: DeserializeHandler<Input, Output>,
15+
context: HandlerExecutionContext
16+
): DeserializeHandler<Input, Output> => async (
17+
args: DeserializeHandlerArguments<Input>
18+
): Promise<DeserializeHandlerOutput<Output>> => {
19+
const { logger, outputFilterSensitiveLog } = context;
20+
21+
const { response } = await next(args);
22+
23+
if (typeof logger?.debug === "function") {
24+
logger.debug({
25+
httpResponse: response,
26+
});
27+
}
28+
29+
const parsed = await deserializer(response, options);
30+
31+
// Log parsed after $metadata is removed in https://github.com/aws/aws-sdk-js-v3/issues/1490
32+
const { $metadata, ...outputWithoutMetadata } = parsed;
33+
34+
if (typeof logger?.info === "function") {
35+
logger.info({
36+
output: outputFilterSensitiveLog(outputWithoutMetadata),
37+
});
38+
}
39+
40+
return {
41+
response,
42+
output: parsed as Output,
2243
};
23-
}
44+
};

0 commit comments

Comments
 (0)