Fix azure auth error display (#18110)

* Fix azure auth error display

* Don't localize command

* Only show localized error string
This commit is contained in:
Charles Gagnon
2022-01-19 14:45:28 -08:00
committed by GitHub
parent 1245829f0d
commit 8e1a1c2797
2 changed files with 13 additions and 14 deletions

View File

@@ -103,11 +103,12 @@ export abstract class AzureAuth implements vscode.Disposable {
if (ex instanceof AzureAuthError) { if (ex instanceof AzureAuthError) {
if (loginComplete) { if (loginComplete) {
loginComplete.reject(ex); loginComplete.reject(ex);
Logger.error(ex);
} else { } else {
void vscode.window.showErrorMessage(ex.getPrintableString()); void vscode.window.showErrorMessage(ex.message);
Logger.error(ex.originalMessageAndException);
} }
} }
Logger.error(ex);
return { return {
canceled: false canceled: false
}; };
@@ -139,9 +140,11 @@ export abstract class AzureAuth implements vscode.Disposable {
return await this.hydrateAccount(tokenResult, this.getTokenClaims(tokenResult.token)); return await this.hydrateAccount(tokenResult, this.getTokenClaims(tokenResult.token));
} catch (ex) { } catch (ex) {
if (ex instanceof AzureAuthError) { if (ex instanceof AzureAuthError) {
void vscode.window.showErrorMessage(ex.getPrintableString()); void vscode.window.showErrorMessage(ex.message);
Logger.error(ex.originalMessageAndException);
} else {
Logger.error(ex);
} }
Logger.error(ex);
account.isStale = true; account.isStale = true;
return account; return account;
} }
@@ -261,7 +264,7 @@ export abstract class AzureAuth implements vscode.Disposable {
if (response.data.error) { if (response.data.error) {
Logger.error('Response error!', response.data); Logger.error('Response error!', response.data);
throw new AzureAuthError(localize('azure.responseError', "Token retrieval failed with an error. Open developer tools to view the error"), 'Token retrieval failed', undefined); throw new AzureAuthError(localize('azure.responseError', "Token retrieval failed with an error. [Open developer tools]({0}) for more details.", 'command:workbench.action.toggleDevTools'), 'Token retrieval failed', undefined);
} }
const accessTokenString = response.data.access_token; const accessTokenString = response.data.access_token;

View File

@@ -4,18 +4,14 @@
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
export class AzureAuthError extends Error { export class AzureAuthError extends Error {
private readonly _originalMessage: string; constructor(localizedMessage: string, public readonly originalMessage: string, private readonly originalException: any) {
constructor(localizedMessage: string, _originalMessage: string, private readonly originalException: any) {
super(localizedMessage); super(localizedMessage);
} }
get originalMessage(): string { /**
return this._originalMessage; * The original message and exception for displaying extra information
} */
public get originalMessageAndException(): string {
getPrintableString(): string {
return JSON.stringify({ return JSON.stringify({
originalMessage: this.originalMessage, originalMessage: this.originalMessage,
originalException: this.originalException originalException: this.originalException