mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Update api to pass more detailed error messaging from azurecore (#22003)
* update api to pass more detailed error messaging from azurecore * fix formatting * fix buid error * fix pr comments * move to azdata.proposed.d.ts * pr comments * Update extensions/azurecore/src/account-provider/auths/azureAuth.ts Co-authored-by: Charles Gagnon <chgagnon@microsoft.com> * refactor * pr comments * Update src/sql/workbench/services/accountManagement/browser/accountManagementService.ts Co-authored-by: Charles Gagnon <chgagnon@microsoft.com> * pr comments * Update src/sql/azdata.proposed.d.ts Co-authored-by: Charles Gagnon <chgagnon@microsoft.com> * Update extensions/azurecore/src/account-provider/auths/azureAuth.ts Co-authored-by: Charles Gagnon <chgagnon@microsoft.com> * fix formatting * fix compile error * fix compile error * pr comments --------- Co-authored-by: Charles Gagnon <chgagnon@microsoft.com>
This commit is contained in:
@@ -145,14 +145,21 @@ export abstract class AzureAuth implements vscode.Disposable {
|
|||||||
Logger.error(ex.originalMessageAndException);
|
Logger.error(ex.originalMessageAndException);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
const message = ex.errorMessage || ex.message;
|
||||||
|
if (message) {
|
||||||
|
loginComplete?.reject(new AzureAuthError(message, message, undefined));
|
||||||
|
return {
|
||||||
|
canceled: false,
|
||||||
|
errorCode: ex.errorCode,
|
||||||
|
errorMessage: message
|
||||||
|
};
|
||||||
|
}
|
||||||
Logger.error(ex);
|
Logger.error(ex);
|
||||||
|
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
canceled: false
|
canceled: false
|
||||||
};
|
};
|
||||||
} finally {
|
|
||||||
loginComplete?.reject(new AzureAuthError(localize('azureAuth.unidentifiedError', "Unidentified error with azure authentication"), 'Unidentified error with azure auth', undefined));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
12
src/sql/azdata.proposed.d.ts
vendored
12
src/sql/azdata.proposed.d.ts
vendored
@@ -432,6 +432,18 @@ declare module 'azdata' {
|
|||||||
azurePortalEndpoint?: string;
|
azurePortalEndpoint?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface PromptFailedResult {
|
||||||
|
/**
|
||||||
|
* Error code used for non-user cancelled sign in errors
|
||||||
|
*/
|
||||||
|
errorCode?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error message used for non-user cancelled sign in errors
|
||||||
|
*/
|
||||||
|
errorMessage?: string;
|
||||||
|
}
|
||||||
|
|
||||||
export namespace diagnostics {
|
export namespace diagnostics {
|
||||||
/**
|
/**
|
||||||
* Represents a diagnostics provider of accounts.
|
* Represents a diagnostics provider of accounts.
|
||||||
|
|||||||
@@ -143,15 +143,18 @@ export class AccountManagementService implements IAccountManagementService {
|
|||||||
return this.doWithProvider(providerId, async (provider) => {
|
return this.doWithProvider(providerId, async (provider) => {
|
||||||
const notificationHandler = this._notificationService.notify(loginNotification);
|
const notificationHandler = this._notificationService.notify(loginNotification);
|
||||||
try {
|
try {
|
||||||
let account = await provider.provider.prompt();
|
let accountResult = await provider.provider.prompt();
|
||||||
if (this.isCanceledResult(account)) {
|
if (!this.isAccountResult(accountResult)) {
|
||||||
return;
|
if (accountResult.canceled === true) {
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
throw new Error(localize('addAccountFailedMessage', `${0} \nError Message: ${1}`, accountResult.errorCode, accountResult.errorMessage));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
let result = await this._accountStore.addOrUpdate(accountResult);
|
||||||
let result = await this._accountStore.addOrUpdate(account);
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
this._logService.error('adding account failed');
|
this._logService.error('adding account failed');
|
||||||
throw Error('Adding account failed, check Azure Accounts log for more info.')
|
throw new Error(localize('addAccountFailedGeneric', 'Adding account failed, check Azure Accounts log for more info.'));
|
||||||
}
|
}
|
||||||
if (result.accountAdded) {
|
if (result.accountAdded) {
|
||||||
// Add the account to the list
|
// Add the account to the list
|
||||||
@@ -190,8 +193,8 @@ export class AccountManagementService implements IAccountManagementService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private isCanceledResult(result: azdata.Account | azdata.PromptFailedResult): result is azdata.PromptFailedResult {
|
private isAccountResult(result: azdata.Account | azdata.PromptFailedResult): result is azdata.Account {
|
||||||
return (<azdata.PromptFailedResult>result).canceled;
|
return typeof (<azdata.Account>result).displayInfo === 'object';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -200,23 +203,25 @@ export class AccountManagementService implements IAccountManagementService {
|
|||||||
* @return Promise to return an account
|
* @return Promise to return an account
|
||||||
*/
|
*/
|
||||||
public refreshAccount(account: azdata.Account): Promise<azdata.Account> {
|
public refreshAccount(account: azdata.Account): Promise<azdata.Account> {
|
||||||
let self = this;
|
|
||||||
|
|
||||||
return this.doWithProvider(account.key.providerId, async (provider) => {
|
return this.doWithProvider(account.key.providerId, async (provider) => {
|
||||||
let refreshedAccount = await provider.provider.refresh(account);
|
let refreshedAccount = await provider.provider.refresh(account);
|
||||||
if (self.isCanceledResult(refreshedAccount)) {
|
if (!this.isAccountResult(refreshedAccount)) {
|
||||||
// Pattern here is to throw if this fails. Handled upstream.
|
if (refreshedAccount.canceled) {
|
||||||
throw new Error(localize('refreshFailed', "Refresh account was canceled by the user"));
|
// Pattern here is to throw if this fails. Handled upstream.
|
||||||
|
throw new Error(localize('refreshCanceled', "Refresh account was canceled by the user"));
|
||||||
|
} else {
|
||||||
|
throw new Error(localize('refreshFailed', `${0} \nError Message: ${1}`, refreshedAccount.errorCode, refreshedAccount.errorMessage));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
account = refreshedAccount;
|
account = refreshedAccount;
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = await self._accountStore.addOrUpdate(account);
|
let result = await this._accountStore.addOrUpdate(account);
|
||||||
if (result.accountAdded) {
|
if (result.accountAdded) {
|
||||||
// Double check that there isn't a matching account
|
// Double check that there isn't a matching account
|
||||||
let indexToRemove = this.findAccountIndex(provider.accounts, result.changedAccount);
|
let indexToRemove = this.findAccountIndex(provider.accounts, result.changedAccount);
|
||||||
if (indexToRemove >= 0) {
|
if (indexToRemove >= 0) {
|
||||||
self._accountStore.remove(provider.accounts[indexToRemove].key);
|
this._accountStore.remove(provider.accounts[indexToRemove].key);
|
||||||
provider.accounts.splice(indexToRemove, 1);
|
provider.accounts.splice(indexToRemove, 1);
|
||||||
}
|
}
|
||||||
// Add the account to the list
|
// Add the account to the list
|
||||||
@@ -232,7 +237,7 @@ export class AccountManagementService implements IAccountManagementService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.fireAccountListUpdate(provider, result.accountAdded);
|
this.fireAccountListUpdate(provider, result.accountAdded);
|
||||||
return result.changedAccount!;
|
return result.changedAccount!;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user