@@ -608,14 +608,23 @@ export class DynamicAuthProvider implements vscode.AuthenticationProvider {
608
608
tokenRequest . append ( 'client_secret' , this . _clientSecret ) ;
609
609
}
610
610
611
- const response = await fetch ( this . _serverMetadata . token_endpoint , {
612
- method : 'POST' ,
613
- headers : {
614
- 'Content-Type' : 'application/x-www-form-urlencoded' ,
615
- 'Accept' : 'application/json'
616
- } ,
617
- body : tokenRequest . toString ( )
618
- } ) ;
611
+ this . _logger . info ( 'Exchanging authorization code for token...' ) ;
612
+ this . _logger . trace ( `Url: ${ this . _serverMetadata . token_endpoint } ` ) ;
613
+ this . _logger . trace ( `Token request body: ${ tokenRequest . toString ( ) } ` ) ;
614
+ let response : Response ;
615
+ try {
616
+ response = await fetch ( this . _serverMetadata . token_endpoint , {
617
+ method : 'POST' ,
618
+ headers : {
619
+ 'Content-Type' : 'application/x-www-form-urlencoded' ,
620
+ 'Accept' : 'application/json'
621
+ } ,
622
+ body : tokenRequest . toString ( )
623
+ } ) ;
624
+ } catch ( err ) {
625
+ this . _logger . error ( `Failed to exchange authorization code for token: ${ err } ` ) ;
626
+ throw new Error ( `Failed to exchange authorization code for token: ${ err } ` ) ;
627
+ }
619
628
620
629
if ( ! response . ok ) {
621
630
const text = await response . text ( ) ;
@@ -624,6 +633,7 @@ export class DynamicAuthProvider implements vscode.AuthenticationProvider {
624
633
625
634
const result = await response . json ( ) ;
626
635
if ( isAuthorizationTokenResponse ( result ) ) {
636
+ this . _logger . info ( `Successfully exchanged authorization code for token.` ) ;
627
637
return result ;
628
638
} else if ( isAuthorizationErrorResponse ( result ) && result . error === AuthorizationErrorType . InvalidClient ) {
629
639
this . _logger . warn ( `Client ID (${ this . _clientId } ) was invalid, generated a new one.` ) ;
0 commit comments