Skip to content

Commit 621d66f

Browse files
committed
Amending http client handling and adding error details to trace
1 parent 320939f commit 621d66f

File tree

4 files changed

+31
-10
lines changed

4 files changed

+31
-10
lines changed

src/ServiceManagement/Sql/Commands.SqlDatabase.Test/UnitTests/MockServer/MockHttpServer.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,6 @@ public static void SetupCertificates()
177177
AzureSMCmdlet.CurrentProfile = profile;
178178
AzureSession.DataStore = new MemoryDataStore();
179179
AzureSession.AuthenticationFactory = new MockTokenAuthenticationFactory();
180-
// Use the default client factory for sql tests
181-
AzureSession.ClientFactory = new ClientFactory();
182180
ProfileClient client = new ProfileClient(profile);
183181
client.AddOrSetAccount( new AzureAccount
184182
{

src/ServiceManagement/Sql/Commands.SqlDatabase/Services/Common/SqlDatabaseExceptionHandler.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ public static void WriteErrorDetails(
4545
{
4646
string requestId;
4747
ErrorRecord errorRecord = RetrieveExceptionDetails(exception, out requestId);
48+
if (!string.IsNullOrEmpty(exception.StackTrace))
49+
{
50+
cmdlet.WriteWarning(string.Format("Received exception: {0}\n Stack trace: {1}", exception.Message, exception.StackTrace));
51+
var innerException = exception.InnerException;
52+
while (innerException != null)
53+
{
54+
cmdlet.WriteWarning(string.Format("Inner exception: {0}\n Stack trace: {1}", innerException.Message, innerException.StackTrace));
55+
}
56+
}
4857

4958
// Write the request Id as a warning
5059
if (requestId != null)

src/ServiceManagement/Sql/Commands.SqlDatabase/Services/Server/ServerDataServiceCertAuth.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,12 +1314,19 @@ private RestoreDatabaseOperation CreateRestoreDatabaseOperationFromResponse(Rest
13141314
/// <param name="sqlManagementClient">The client to add the headers on.</param>
13151315
private void AddTracingHeaders(SqlManagementClient sqlManagementClient)
13161316
{
1317-
sqlManagementClient.HttpClient.DefaultRequestHeaders.Add(
1318-
Constants.ClientSessionIdHeaderName,
1319-
this.ClientSessionId);
1320-
sqlManagementClient.HttpClient.DefaultRequestHeaders.Add(
1321-
Constants.ClientRequestIdHeaderName,
1322-
this.ClientRequestId);
1317+
try
1318+
{
1319+
sqlManagementClient.HttpClient.DefaultRequestHeaders.Add(
1320+
Constants.ClientSessionIdHeaderName,
1321+
this.ClientSessionId);
1322+
sqlManagementClient.HttpClient.DefaultRequestHeaders.Add(
1323+
Constants.ClientRequestIdHeaderName,
1324+
this.ClientRequestId);
1325+
}
1326+
catch
1327+
{
1328+
// do not fail if the http client is being reused
1329+
}
13231330
}
13241331

13251332
/// <summary>

src/ServiceManagement/Sql/Commands.SqlDatabase/SqlDatabaseCmdletBase.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,15 @@ protected SqlManagementClient GetCurrentSqlClient()
6464
AzureSubscription subscription = Profile.Context.Subscription;
6565
SqlDatabaseCmdletBase.ValidateSubscription(subscription);
6666
SqlManagementClient client = AzureSession.ClientFactory.CreateClient<SqlManagementClient>(Profile, subscription, AzureEnvironment.Endpoint.ServiceManagement);
67-
client.HttpClient.DefaultRequestHeaders.Add(Constants.ClientSessionIdHeaderName, clientSessionId);
68-
client.HttpClient.DefaultRequestHeaders.Add(Constants.ClientRequestIdHeaderName, clientRequestId);
67+
try
68+
{
69+
client.HttpClient.DefaultRequestHeaders.Add(Constants.ClientSessionIdHeaderName, clientSessionId);
70+
client.HttpClient.DefaultRequestHeaders.Add(Constants.ClientRequestIdHeaderName, clientRequestId);
71+
}
72+
catch
73+
{
74+
// do not fail if the http client is being reused
75+
}
6976
return client;
7077
}
7178

0 commit comments

Comments
 (0)