mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Handle some promises better in cms (#7166)
* handle some promises better in cms
* 💄
This commit is contained in:
@@ -392,7 +392,7 @@ export class ConnectionManagementService extends Disposable implements IConnecti
|
|||||||
if (!tokenFillSuccess) {
|
if (!tokenFillSuccess) {
|
||||||
throw new Error(nls.localize('connection.noAzureAccount', "Failed to get Azure account token for connection"));
|
throw new Error(nls.localize('connection.noAzureAccount', "Failed to get Azure account token for connection"));
|
||||||
}
|
}
|
||||||
return this.createNewConnection(uri, connection).then(connectionResult => {
|
return this.createNewConnection(uri, connection).then(async connectionResult => {
|
||||||
if (connectionResult && connectionResult.connected) {
|
if (connectionResult && connectionResult.connected) {
|
||||||
// The connected succeeded so add it to our active connections now, optionally adding it to the MRU based on
|
// The connected succeeded so add it to our active connections now, optionally adding it to the MRU based on
|
||||||
// the options.saveTheConnection setting
|
// the options.saveTheConnection setting
|
||||||
@@ -403,7 +403,7 @@ export class ConnectionManagementService extends Disposable implements IConnecti
|
|||||||
callbacks.onConnectSuccess(options.params, connectionResult.connectionProfile);
|
callbacks.onConnectSuccess(options.params, connectionResult.connectionProfile);
|
||||||
}
|
}
|
||||||
if (options.saveTheConnection) {
|
if (options.saveTheConnection) {
|
||||||
this.saveToSettings(uri, connection).then(value => {
|
await this.saveToSettings(uri, connection).then(value => {
|
||||||
this._onAddConnectionProfile.fire(connection);
|
this._onAddConnectionProfile.fire(connection);
|
||||||
this.doActionsAfterConnectionComplete(value, options);
|
this.doActionsAfterConnectionComplete(value, options);
|
||||||
});
|
});
|
||||||
@@ -518,7 +518,7 @@ export class ConnectionManagementService extends Disposable implements IConnecti
|
|||||||
if (!this.focusDashboard(connectionProfile)) {
|
if (!this.focusDashboard(connectionProfile)) {
|
||||||
let dashboardInput: DashboardInput = this._instantiationService ? this._instantiationService.createInstance(DashboardInput, connectionProfile) : undefined;
|
let dashboardInput: DashboardInput = this._instantiationService ? this._instantiationService.createInstance(DashboardInput, connectionProfile) : undefined;
|
||||||
return dashboardInput.initializedPromise.then(() => {
|
return dashboardInput.initializedPromise.then(() => {
|
||||||
this._editorService.openEditor(dashboardInput, { pinned: true }, ACTIVE_GROUP);
|
return this._editorService.openEditor(dashboardInput, { pinned: true }, ACTIVE_GROUP);
|
||||||
}).then(() => true);
|
}).then(() => true);
|
||||||
} else {
|
} else {
|
||||||
return Promise.resolve(true);
|
return Promise.resolve(true);
|
||||||
@@ -1145,33 +1145,25 @@ export class ConnectionManagementService extends Disposable implements IConnecti
|
|||||||
// Disconnect if connected
|
// Disconnect if connected
|
||||||
let uri = Utils.generateUri(connection);
|
let uri = Utils.generateUri(connection);
|
||||||
if (this.isConnected(uri) || this.isConnecting(uri)) {
|
if (this.isConnected(uri) || this.isConnecting(uri)) {
|
||||||
this.doDisconnect(uri, connection).then((result) => {
|
return this.doDisconnect(uri, connection).then((result) => {
|
||||||
if (result) {
|
if (result) {
|
||||||
// Remove profile from configuration
|
// Remove profile from configuration
|
||||||
this._connectionStore.deleteConnectionFromConfiguration(connection).then(() => {
|
return this._connectionStore.deleteConnectionFromConfiguration(connection).then(() => {
|
||||||
this._onDeleteConnectionProfile.fire();
|
this._onDeleteConnectionProfile.fire();
|
||||||
Promise.resolve(true);
|
return true;
|
||||||
}).catch(err => {
|
|
||||||
// Reject promise if error occurred writing to settings
|
|
||||||
Promise.reject(err);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// If connection fails to disconnect, resolve promise with false
|
return false;
|
||||||
Promise.resolve(false);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Remove disconnected profile from settings
|
// Remove disconnected profile from settings
|
||||||
this._connectionStore.deleteConnectionFromConfiguration(connection).then(() => {
|
return this._connectionStore.deleteConnectionFromConfiguration(connection).then(() => {
|
||||||
this._onDeleteConnectionProfile.fire();
|
this._onDeleteConnectionProfile.fire();
|
||||||
Promise.resolve(true);
|
return true;
|
||||||
}).catch(err => {
|
|
||||||
// Reject promise if error ocurred writing to settings
|
|
||||||
Promise.reject(err);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return Promise.resolve(undefined);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1193,20 +1185,13 @@ export class ConnectionManagementService extends Disposable implements IConnecti
|
|||||||
});
|
});
|
||||||
|
|
||||||
// When all the disconnect promises resolve, remove profiles from config
|
// When all the disconnect promises resolve, remove profiles from config
|
||||||
Promise.all(disconnected).then(() => {
|
return Promise.all(disconnected).then(() => {
|
||||||
// Remove profiles and groups from config
|
// Remove profiles and groups from config
|
||||||
this._connectionStore.deleteGroupFromConfiguration(group).then(() => {
|
return this._connectionStore.deleteGroupFromConfiguration(group).then(() => {
|
||||||
this._onDeleteConnectionProfile.fire();
|
this._onDeleteConnectionProfile.fire();
|
||||||
Promise.resolve(true);
|
return true;
|
||||||
}).catch(err => {
|
|
||||||
// If saving to config fails, reject promise with false
|
|
||||||
return Promise.reject(false);
|
|
||||||
});
|
});
|
||||||
}).catch(err => {
|
}).catch(() => false);
|
||||||
// If disconnecting all connected profiles fails, resolve promise with false
|
|
||||||
return Promise.resolve(false);
|
|
||||||
});
|
|
||||||
return Promise.resolve(undefined);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private _notifyDisconnected(connectionProfile: interfaces.IConnectionProfile, connectionUri: string): void {
|
private _notifyDisconnected(connectionProfile: interfaces.IConnectionProfile, connectionUri: string): void {
|
||||||
|
|||||||
Reference in New Issue
Block a user