@@ -75,6 +75,8 @@ import { getServiceEnvVarConfig } from '../vscode/env'
7575import { AwsCommand } from '../awsClientBuilderV3'
7676import { ClientWrapper } from './clientWrapper'
7777import { StandardRetryStrategy } from '@smithy/util-retry'
78+ import { ServiceException } from '@aws-sdk/smithy-client'
79+ import { AccessDeniedException } from '@aws-sdk/client-sso-oidc'
7880
7981const requiredDevEnvProps = [
8082 'id' ,
@@ -363,22 +365,26 @@ class CodeCatalystClientInternal extends ClientWrapper<CodeCatalystSDKClient> {
363365 resolve ( data )
364366 } catch ( e ) {
365367 const error = e as Error
366- if ( isAccessDeniedError ( e ) ) {
368+ if ( error instanceof ServiceException && isAccessDeniedError ( error ) ) {
367369 CodeCatalystClientInternal . identityCache . delete ( bearerToken )
368370 }
369- if ( silent ) {
370- if ( defaultVal === undefined ) {
371- throw Error ( )
372- }
371+ if ( silent && defaultVal !== undefined ) {
373372 resolve ( defaultVal )
374373 } else {
375- reject ( new ToolkitError ( `CodeCatalyst: request failed with error` , { cause : error } ) )
374+ // SDKv3 does not have error codes so we use the name instead (see: https://github.com/aws/aws-sdk-js-v3/issues/759)
375+ reject (
376+ new ToolkitError ( `CodeCatalyst: request failed with error` , { cause : error , code : error . name } )
377+ )
376378 }
377379 }
378380 } )
379381
380- function isAccessDeniedError ( e : any ) : boolean {
381- return e . code === 'AccessDeniedException' || e . statusCode === 401
382+ function isAccessDeniedError ( e : ServiceException ) : boolean {
383+ return (
384+ e . $response ?. statusCode === 403 ||
385+ e . $response ?. statusCode === 401 ||
386+ e . name === AccessDeniedException . name
387+ )
382388 }
383389 }
384390
0 commit comments