@@ -42,6 +42,7 @@ import { partialClone } from './utilities/collectionUtils'
42
42
import { selectFrom } from './utilities/tsUtils'
43
43
import { once } from './utilities/functionUtils'
44
44
import { isWeb } from './extensionGlobals'
45
+ import { AuthorizationPendingException } from '@aws-sdk/client-sso-oidc'
45
46
46
47
export type AwsClientConstructor < C > = new ( o : AwsClientOptions ) => C
47
48
export type AwsCommandConstructor < CommandInput extends object , Command extends AwsCommand < CommandInput , object > > = new (
@@ -175,8 +176,8 @@ export class AWSClientBuilderV3 {
175
176
}
176
177
177
178
const service = new serviceOptions . serviceClient ( opt )
178
- service . middlewareStack . add ( telemetryMiddleware , { step : 'deserialize' } )
179
- service . middlewareStack . add ( loggingMiddleware , { step : 'finalizeRequest' } )
179
+ service . middlewareStack . add ( defaultDeserializeMiddleware , { step : 'deserialize' } )
180
+ service . middlewareStack . add ( finalizeLoggingMiddleware , { step : 'finalizeRequest' } )
180
181
service . middlewareStack . add ( getEndpointMiddleware ( serviceOptions . settings ) , { step : 'build' } )
181
182
182
183
if ( keepAlive ) {
@@ -211,20 +212,13 @@ export function recordErrorTelemetry(err: Error, serviceName?: string) {
211
212
} )
212
213
}
213
214
214
- function logAndThrow ( e : any , serviceId : string , errorMessageAppend : string ) : never {
215
- if ( e instanceof Error ) {
216
- recordErrorTelemetry ( e , serviceId )
217
- getLogger ( ) . error ( 'API Response %s: %O' , errorMessageAppend , e )
218
- }
219
- throw e
220
- }
221
-
222
- const telemetryMiddleware : DeserializeMiddleware < any , any > =
215
+ export const defaultDeserializeMiddleware : DeserializeMiddleware < any , any > =
223
216
( next : DeserializeHandler < any , any > , context : HandlerExecutionContext ) => async ( args : any ) =>
224
- emitOnRequest ( next , context , args )
217
+ onDeserialize ( next , context , args )
225
218
226
- const loggingMiddleware : FinalizeRequestMiddleware < any , any > = ( next : FinalizeHandler < any , any > ) => async ( args : any ) =>
227
- logOnRequest ( next , args )
219
+ export const finalizeLoggingMiddleware : FinalizeRequestMiddleware < any , any > =
220
+ ( next : FinalizeHandler < any , any > ) => async ( args : any ) =>
221
+ logOnFinalize ( next , args )
228
222
229
223
function getEndpointMiddleware ( settings : DevSettings = DevSettings . instance ) : BuildMiddleware < any , any > {
230
224
return ( next : BuildHandler < any , any > , context : HandlerExecutionContext ) => async ( args : any ) =>
@@ -234,32 +228,36 @@ function getEndpointMiddleware(settings: DevSettings = DevSettings.instance): Bu
234
228
const keepAliveMiddleware : BuildMiddleware < any , any > = ( next : BuildHandler < any , any > ) => async ( args : any ) =>
235
229
addKeepAliveHeader ( next , args )
236
230
237
- export async function emitOnRequest ( next : DeserializeHandler < any , any > , context : HandlerExecutionContext , args : any ) {
231
+ export async function onDeserialize ( next : DeserializeHandler < any , any > , context : HandlerExecutionContext , args : any ) {
238
232
if ( ! HttpResponse . isInstance ( args . request ) ) {
239
233
return next ( args )
240
234
}
241
- const serviceId = getServiceId ( context as object )
242
235
const { hostname, path } = args . request
236
+ const serviceId = getServiceId ( context as object )
243
237
const logTail = `(${ hostname } ${ path } )`
244
238
try {
245
239
const result = await next ( args )
246
240
if ( HttpResponse . isInstance ( result . response ) ) {
247
- // TODO: omit credentials / sensitive info from the telemetry.
248
- const output = partialClone ( result . output , 3 )
241
+ const output = partialClone ( result . output , 3 , [ 'clientSecret' , 'accessToken' , 'refreshToken' ] , '[omitted]' )
249
242
getLogger ( ) . debug ( `API Response %s: %O` , logTail , output )
250
243
}
251
244
return result
252
- } catch ( e : any ) {
253
- logAndThrow ( e , serviceId , logTail )
245
+ } catch ( e : unknown ) {
246
+ if ( e instanceof Error && ! ( e instanceof AuthorizationPendingException ) ) {
247
+ const err = { ...e , name : e . name , mesage : e . message }
248
+ delete err [ 'stack' ]
249
+ recordErrorTelemetry ( err , serviceId )
250
+ getLogger ( ) . error ( 'API Response %s: %O' , logTail , err )
251
+ }
252
+ throw e
254
253
}
255
254
}
256
255
257
- export async function logOnRequest ( next : FinalizeHandler < any , any > , args : any ) {
256
+ export async function logOnFinalize ( next : FinalizeHandler < any , any > , args : any ) {
258
257
const request = args . request
259
258
if ( HttpRequest . isInstance ( args . request ) ) {
260
259
const { hostname, path } = request
261
- // TODO: omit credentials / sensitive info from the logs.
262
- const input = partialClone ( args . input , 3 )
260
+ const input = partialClone ( args . input , 3 , [ 'clientSecret' , 'accessToken' , 'refreshToken' ] , '[omitted]' )
263
261
getLogger ( ) . debug ( `API Request (%s %s): %O` , hostname , path , input )
264
262
}
265
263
return next ( args )
0 commit comments