handle azure account load error (#13940)

* handle azure account load error

* comments
This commit is contained in:
Alan Ren
2021-01-14 10:40:31 -08:00
committed by GitHub
parent c39c20cd4b
commit b6c80557ba
2 changed files with 22 additions and 10 deletions

View File

@@ -53,20 +53,32 @@ export class ConnectionDialogTreeProvider implements vscode.TreeDataProvider<Tre
return [AzureResourceMessageTreeNode.create(localize('azure.resource.tree.treeProvider.loadingLabel', "Loading ..."), undefined)];
}
try {
if (this.accounts && this.accounts.length > 0) {
const accountNodes: FlatAccountTreeNode[] = [];
for (const account of this.accounts) {
if (this.accounts && this.accounts.length > 0) {
const accountNodes: FlatAccountTreeNode[] = [];
const errorMessages: string[] = [];
// We are doing sequential account loading to avoid the Azure request throttling
for (const account of this.accounts) {
try {
const accountNode = new FlatAccountTreeNode(account, this.appContext, this);
await accountNode.updateLabel();
accountNodes.push(accountNode);
}
return accountNodes;
} else {
return [new AzureResourceAccountNotSignedInTreeNode()];
catch (error) {
errorMessages.push(AzureResourceErrorMessageUtil.getErrorMessage(error));
}
}
} catch (error) {
return [AzureResourceMessageTreeNode.create(AzureResourceErrorMessageUtil.getErrorMessage(error), undefined)];
if (errorMessages.length > 0) {
const showAccountsAction = localize('azure.resource.tree.treeProvider.openAccountsDialog', "Show Azure accounts");
vscode.window.showErrorMessage(localize('azure.resource.tree.treeProvider.accountLoadError', "Failed to load some Azure accounts. {0}", errorMessages.join(',')), showAccountsAction).then(result => {
if (result === showAccountsAction) {
vscode.commands.executeCommand('azure.resource.signin');
}
});
}
return accountNodes;
} else {
return [new AzureResourceAccountNotSignedInTreeNode()];
}
}

View File

@@ -127,7 +127,7 @@ async function getSubscriptionInfo(account: AzureAccount, subscriptionService: I
subscriptions.push(...(await subscriptionService.getSubscriptions(account, new TokenCredentials(token.token, token.tokenType), tenant.id) || <azureResource.AzureResourceSubscription[]>[]));
}
} catch (error) {
throw new AzureResourceCredentialError(localize('azure.resource.tree.accountTreeNode.credentialError', "Failed to get credential for account {0}. Please refresh the account.", account.key.accountId), error);
throw new AzureResourceCredentialError(localize('azure.resource.tree.accountTreeNode.credentialError', "Failed to get credential for account {0}. Please go to the accounts dialog and refresh the account.", account.key.accountId), error);
}
const total = subscriptions.length;
let selected = total;