Skip to content

Commit

Permalink
refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
sourabh1007 committed Sep 14, 2023
1 parent 35001c5 commit 0cfa208
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions Microsoft.Azure.Cosmos/src/Telemetry/TelemetryToServiceHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ private async Task RetrieveConfigAndInitiateTelemetryAsync()
this.InitializeClientTelemetry(
clientConfig: databaseAccountClientConfigs.Result);
}
else if (databaseAccountClientConfigs.Exception is ObjectDisposedException)
{
DefaultTrace.TraceWarning("Client is being disposed for {0} at {1}", serviceEndpointWithPath, DateTime.UtcNow);
break;
}
else if (!this.cancellationTokenSource.IsCancellationRequested)
{
DefaultTrace.TraceWarning("Exception while calling client config {0} ", databaseAccountClientConfigs.Exception);
Expand Down Expand Up @@ -149,19 +154,17 @@ await cosmosAuthorization.AddAuthorizationHeaderAsync(
if (responseMessage.StatusCode == System.Net.HttpStatusCode.BadRequest)
{
string responseFromGateway = await responseMessage.Content.ReadAsStringAsync();
throw new InvalidOperationException($"Client Config API is not enabled at compute gateway. Response is {responseFromGateway}");
return TryCatch<AccountClientConfiguration>.FromException(
new InvalidOperationException($"Client Config API is not enabled at compute gateway. Response is {responseFromGateway}"));
}

using (DocumentServiceResponse documentServiceResponse = await ClientExtensions.ParseResponseAsync(responseMessage))
{
return TryCatch<AccountClientConfiguration>.FromResult(CosmosResource.FromStream<AccountClientConfiguration>(documentServiceResponse));
return TryCatch<AccountClientConfiguration>.FromResult(
CosmosResource.FromStream<AccountClientConfiguration>(documentServiceResponse));
}
}
}
catch (ObjectDisposedException)
{
throw new OperationCanceledException($"Client is being disposed for {clientConfigEndpoint} at {DateTime.UtcNow}");
}
catch (Exception ex)
{
DefaultTrace.TraceWarning("Exception while calling client config {0}", ex);
Expand Down

0 comments on commit 0cfa208

Please sign in to comment.