From 8e1a1c2797429e640767d94002bfa0b5b829bef3 Mon Sep 17 00:00:00 2001 From: Charles Gagnon Date: Wed, 19 Jan 2022 14:45:28 -0800 Subject: [PATCH] Fix azure auth error display (#18110) * Fix azure auth error display * Don't localize command * Only show localized error string --- .../src/account-provider/auths/azureAuth.ts | 13 ++++++++----- .../src/account-provider/auths/azureAuthError.ts | 14 +++++--------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/extensions/azurecore/src/account-provider/auths/azureAuth.ts b/extensions/azurecore/src/account-provider/auths/azureAuth.ts index 0945504d04..b16ccdddf7 100644 --- a/extensions/azurecore/src/account-provider/auths/azureAuth.ts +++ b/extensions/azurecore/src/account-provider/auths/azureAuth.ts @@ -103,11 +103,12 @@ export abstract class AzureAuth implements vscode.Disposable { if (ex instanceof AzureAuthError) { if (loginComplete) { loginComplete.reject(ex); + Logger.error(ex); } else { - void vscode.window.showErrorMessage(ex.getPrintableString()); + void vscode.window.showErrorMessage(ex.message); + Logger.error(ex.originalMessageAndException); } } - Logger.error(ex); return { canceled: false }; @@ -139,9 +140,11 @@ export abstract class AzureAuth implements vscode.Disposable { return await this.hydrateAccount(tokenResult, this.getTokenClaims(tokenResult.token)); } catch (ex) { 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; return account; } @@ -261,7 +264,7 @@ export abstract class AzureAuth implements vscode.Disposable { if (response.data.error) { 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; diff --git a/extensions/azurecore/src/account-provider/auths/azureAuthError.ts b/extensions/azurecore/src/account-provider/auths/azureAuthError.ts index 5234bbba5f..f94c489edf 100644 --- a/extensions/azurecore/src/account-provider/auths/azureAuthError.ts +++ b/extensions/azurecore/src/account-provider/auths/azureAuthError.ts @@ -4,18 +4,14 @@ *--------------------------------------------------------------------------------------------*/ export class AzureAuthError extends Error { - private readonly _originalMessage: string; - - constructor(localizedMessage: string, _originalMessage: string, private readonly originalException: any) { + constructor(localizedMessage: string, public readonly originalMessage: string, private readonly originalException: any) { super(localizedMessage); - } - get originalMessage(): string { - return this._originalMessage; - } - - getPrintableString(): string { + /** + * The original message and exception for displaying extra information + */ + public get originalMessageAndException(): string { return JSON.stringify({ originalMessage: this.originalMessage, originalException: this.originalException