Skip to content

Commit

Permalink
added missing request/reponse logging to asynch API methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan Steiner committed Oct 6, 2023
1 parent 5c97f0c commit f631ea1
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion build/src/PureCloudPlatform.Client.V2/Client/ApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,23 @@ private void HandleExpiredAccessToken()
}

RestClient = new RestClient(options);

var fullUrl = RestClient.BuildUri(request);
string url = fullUrl == null ? path : fullUrl.ToString();
do
{
response = await RestClient.ExecuteAsync(request);
}while(retry.ShouldRetry(response));

Configuration.Logger.Debug(method.ToString(), url, postBody, (int)response.StatusCode, headerParams);
Configuration.Logger.Trace(method.ToString(), url, postBody, (int)response.StatusCode, headerParams, response.Headers?
.Select(header => new
{
Name = header.GetType().GetProperty("Name")?.GetValue(header),
Value = header.GetType().GetProperty("Value")?.GetValue(header)
}).ToDictionary(header => header?.Name?.ToString(), header => header?.Value?.ToString())
?? new Dictionary<string, string>());

} while (retry.ShouldRetry(response));

if ((UsingCodeAuth || UsingClientCredentials) && Configuration.ShouldRefreshAccessToken)
{
Expand All @@ -369,6 +382,16 @@ private void HandleExpiredAccessToken()
}
}

if ((int)response.StatusCode < 200 || (int)response.StatusCode >= 300)
Configuration.Logger.Error(method.ToString(), url, postBody, response.Content, (int)response.StatusCode, headerParams, response.Headers?
.Select(header => new
{
Name = header.GetType().GetProperty("Name")?.GetValue(header),
Value = header.GetType().GetProperty("Value")?.GetValue(header)
}).ToDictionary(header => header?.Name?.ToString(), header => header?.Value?.ToString())
?? new Dictionary<string, string>());


return (Object)response;
}

Expand Down

0 comments on commit f631ea1

Please sign in to comment.