Skip to content

Commit b49ad47

Browse files
A few logs for mcp (microsoft#257919)
* A few logs for mcp * add error logging too
1 parent a8366d1 commit b49ad47

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

src/vs/workbench/api/common/extHostAuthentication.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -608,14 +608,23 @@ export class DynamicAuthProvider implements vscode.AuthenticationProvider {
608608
tokenRequest.append('client_secret', this._clientSecret);
609609
}
610610

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+
}
619628

620629
if (!response.ok) {
621630
const text = await response.text();
@@ -624,6 +633,7 @@ export class DynamicAuthProvider implements vscode.AuthenticationProvider {
624633

625634
const result = await response.json();
626635
if (isAuthorizationTokenResponse(result)) {
636+
this._logger.info(`Successfully exchanged authorization code for token.`);
627637
return result;
628638
} else if (isAuthorizationErrorResponse(result) && result.error === AuthorizationErrorType.InvalidClient) {
629639
this._logger.warn(`Client ID (${this._clientId}) was invalid, generated a new one.`);

0 commit comments

Comments
 (0)