Throw exception on connection failure to be captured by frontend (#2190)

This commit is contained in:
Cheena Malhotra
2023-08-23 18:28:47 -07:00
committed by GitHub
parent 2502e23f43
commit 4e5a7ebe97
7 changed files with 182 additions and 177 deletions

View File

@@ -66,30 +66,22 @@ namespace Microsoft.SqlTools.ServiceLayer.ServerConfigurations
public async Task HandleServerConfigViewRequest(ServerConfigViewRequestParams parameters, RequestContext<ServerConfigViewResponseParams> requestContext)
{
Logger.Verbose("HandleServerConfigViewRequest");
try
ConnectionInfo connInfo;
ConnectionServiceInstance.TryFindConnection(
parameters.OwnerUri,
out connInfo);
if (connInfo == null)
{
ConnectionInfo connInfo;
ConnectionServiceInstance.TryFindConnection(
parameters.OwnerUri,
out connInfo);
if (connInfo == null)
{
await requestContext.SendError(new Exception(SR.ProfilerConnectionNotFound));
}
else
{
var serverConnection = ConnectionService.OpenServerConnection(connInfo);
ServerConfigProperty serverConfig = GetConfig(serverConnection, parameters.ConfigNumber);
await requestContext.SendResult(new ServerConfigViewResponseParams
{
ConfigProperty = serverConfig
});
}
await requestContext.SendError(new Exception(SR.ProfilerConnectionNotFound));
}
catch (Exception e)
else
{
// Exception related to run task will be captured here
await requestContext.SendError(e);
var serverConnection = ConnectionService.OpenServerConnection(connInfo);
ServerConfigProperty serverConfig = GetConfig(serverConnection, parameters.ConfigNumber);
await requestContext.SendResult(new ServerConfigViewResponseParams
{
ConfigProperty = serverConfig
});
}
}
@@ -102,32 +94,24 @@ namespace Microsoft.SqlTools.ServiceLayer.ServerConfigurations
public async Task HandleServerConfigUpdateRequest(ServerConfigUpdateRequestParams parameters, RequestContext<ServerConfigUpdateResponseParams> requestContext)
{
Logger.Verbose("HandleServerConfigUpdateRequest");
try
ConnectionInfo connInfo;
ConnectionServiceInstance.TryFindConnection(
parameters.OwnerUri,
out connInfo);
ServerConfigUpdateResponseParams response = new ServerConfigUpdateResponseParams
{
ConnectionInfo connInfo;
ConnectionServiceInstance.TryFindConnection(
parameters.OwnerUri,
out connInfo);
ServerConfigUpdateResponseParams response = new ServerConfigUpdateResponseParams
{
};
};
if (connInfo == null)
{
await requestContext.SendError(new Exception(SR.ProfilerConnectionNotFound));
}
else
{
var serverConnection = ConnectionService.OpenServerConnection(connInfo);
UpdateConfig(serverConnection, parameters.ConfigNumber, parameters.ConfigValue);
response.ConfigProperty = GetConfig(serverConnection, parameters.ConfigNumber);
await requestContext.SendResult(response);
}
}
catch (Exception e)
if (connInfo == null)
{
// Exception related to run task will be captured here
await requestContext.SendError(e);
await requestContext.SendError(new Exception(SR.ProfilerConnectionNotFound));
}
else
{
var serverConnection = ConnectionService.OpenServerConnection(connInfo);
UpdateConfig(serverConnection, parameters.ConfigNumber, parameters.ConfigValue);
response.ConfigProperty = GetConfig(serverConnection, parameters.ConfigNumber);
await requestContext.SendResult(response);
}
}
@@ -139,31 +123,23 @@ namespace Microsoft.SqlTools.ServiceLayer.ServerConfigurations
public async Task HandleServerConfigListRequest(ServerConfigListRequestParams parameters, RequestContext<ServerConfigListResponseParams> requestContext)
{
Logger.Verbose("HandleServerConfigListRequest");
try
ConnectionInfo connInfo;
ConnectionServiceInstance.TryFindConnection(
parameters.OwnerUri,
out connInfo);
ServerConfigListResponseParams response = new ServerConfigListResponseParams
{
ConnectionInfo connInfo;
ConnectionServiceInstance.TryFindConnection(
parameters.OwnerUri,
out connInfo);
ServerConfigListResponseParams response = new ServerConfigListResponseParams
{
};
};
if (connInfo == null)
{
await requestContext.SendError(new Exception(SR.ProfilerConnectionNotFound));
}
else
{
var serverConnection = ConnectionService.OpenServerConnection(connInfo);
response.ConfigProperties = GetConfigs(serverConnection);
await requestContext.SendResult(response);
}
}
catch (Exception e)
if (connInfo == null)
{
// Exception related to run task will be captured here
await requestContext.SendError(e);
await requestContext.SendError(new Exception(SR.ProfilerConnectionNotFound));
}
else
{
var serverConnection = ConnectionService.OpenServerConnection(connInfo);
response.ConfigProperties = GetConfigs(serverConnection);
await requestContext.SendResult(response);
}
}