Skip to content

Commit

Permalink
improve account and tenant selection error handling (#17476) (#17489)
Browse files Browse the repository at this point in the history
* improve account/tenant selection error handling

* remove extra space from user string
  • Loading branch information
brian-harris committed Oct 26, 2021
1 parent ccbc2f7 commit 6783aa6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
2 changes: 1 addition & 1 deletion extensions/sql-migration/package.json
Expand Up @@ -10,7 +10,7 @@
"aiKey": "AIF-37eefaf0-8022-4671-a3fb-64752724682e",
"engines": {
"vscode": "*",
"azdata": ">=1.29.0"
"azdata": ">=1.33.0"
},
"activationEvents": [
"onDashboardOpen",
Expand Down
2 changes: 1 addition & 1 deletion extensions/sql-migration/src/api/azure.ts
Expand Up @@ -51,7 +51,7 @@ export type AzureProduct = azureResource.AzureGraphResource;

export async function getResourceGroups(account: azdata.Account, subscription: Subscription): Promise<azureResource.AzureResourceResourceGroup[]> {
const api = await getAzureCoreAPI();
const result = await api.getResourceGroups(account, subscription, false);
const result = await api.getResourceGroups(account, subscription, true);
sortResourceArrayByName(result.resourceGroups);
return result.resourceGroups;
}
Expand Down
13 changes: 11 additions & 2 deletions extensions/sql-migration/src/constants/strings.ts
Expand Up @@ -92,10 +92,19 @@ export function accountLinkedMessage(count: number): string {
}
export const AZURE_TENANT = localize('sql.migration.azure.tenant', "Azure AD tenant");
export function ACCOUNT_STALE_ERROR(account: AzureAccount) {
return localize('azure.accounts.accountStaleError', "The access token for selected account '{0}' is no longer valid. Select 'Link account' and refresh the account, or select a different account.", `${account.displayInfo.displayName} (${account.displayInfo.userId})`);
return localize(
'azure.accounts.accountStaleError',
"The access token for selected account '{0}' and tenant '{1}' is no longer valid. Select 'Link account' and refresh the account, or select a different account.",
`${account?.displayInfo?.displayName} (${account?.displayInfo?.userId})`,
`${account?.properties?.tenants[0]?.displayName} (${account?.properties?.tenants[0]?.userId})`);
}
export function ACCOUNT_ACCESS_ERROR(account: AzureAccount, error: Error) {
return localize('azure.accounts.accountAccessError', "An error occurred while accessing the selected account '{0}'. Select 'Link account' and refresh the account, or select a different account. Error '{1}'", `${account.displayInfo.displayName} (${account.displayInfo.userId})`, error.message);
return localize(
'azure.accounts.accountAccessError',
"An error occurred while accessing the selected account '{0}' and tenant '{1}'. Select 'Link account' and refresh the account, or select a different account. Error '{2}'",
`${account?.displayInfo?.displayName} (${account?.displayInfo?.userId})`,
`${account?.properties?.tenants[0]?.displayName} (${account?.properties?.tenants[0]?.userId})`,
error.message);
}

// database backup page
Expand Down
17 changes: 12 additions & 5 deletions extensions/sql-migration/src/wizard/accountsSelectionPage.ts
Expand Up @@ -82,6 +82,7 @@ export class AccountsSelectionPage extends MigrationWizardPage {
}
if (this.migrationStateModel._azureAccount?.isStale) {
this.wizard.message = {
level: azdata.window.MessageLevel.Error,
text: constants.ACCOUNT_STALE_ERROR(this.migrationStateModel._azureAccount)
};
return false;
Expand Down Expand Up @@ -193,8 +194,6 @@ export class AccountsSelectionPage extends MigrationWizardPage {
this.migrationStateModel._targetSubscription = undefined!;
this.migrationStateModel._databaseBackup.subscription = undefined!;
}
const selectedAzureAccount = this.migrationStateModel.getAccount(selectedIndex);
this.migrationStateModel._azureAccount = deepClone(selectedAzureAccount);

}));

Expand Down Expand Up @@ -233,16 +232,24 @@ export class AccountsSelectionPage extends MigrationWizardPage {
public async onPageEnter(pageChangeInfo: azdata.window.WizardPageChangeInfo): Promise<void> {
this.wizard.registerNavigationValidator(async pageChangeInfo => {
try {
if (!this.migrationStateModel._azureAccount?.isStale) {
this.wizard.message = { text: '', };

if (this.migrationStateModel._azureAccount && !this.migrationStateModel._azureAccount?.isStale) {
const subscriptions = await getSubscriptions(this.migrationStateModel._azureAccount);
if (subscriptions?.length > 0) {
return true;
}
}

this.wizard.message = { text: constants.ACCOUNT_STALE_ERROR(this.migrationStateModel._azureAccount) };
this.wizard.message = {
level: azdata.window.MessageLevel.Error,
text: constants.ACCOUNT_STALE_ERROR(this.migrationStateModel._azureAccount),
};
} catch (error) {
this.wizard.message = { text: constants.ACCOUNT_ACCESS_ERROR(this.migrationStateModel._azureAccount, error) };
this.wizard.message = {
level: azdata.window.MessageLevel.Error,
text: constants.ACCOUNT_ACCESS_ERROR(this.migrationStateModel._azureAccount, error),
};
}

return false;
Expand Down

0 comments on commit 6783aa6

Please sign in to comment.