@@ -3,21 +3,42 @@ import {
3
3
DeserializeHandlerArguments ,
4
4
DeserializeHandlerOutput ,
5
5
DeserializeMiddleware ,
6
+ HandlerExecutionContext ,
6
7
ResponseDeserializer ,
7
8
} from "@aws-sdk/types" ;
8
9
9
- export function deserializerMiddleware < Input extends object , Output extends object , RuntimeUtils = any > (
10
+ export const deserializerMiddleware = < Input extends object , Output extends object , RuntimeUtils = any > (
10
11
options : RuntimeUtils ,
11
12
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 ,
22
43
} ;
23
- }
44
+ } ;
0 commit comments