Skip to content

Commit e520144

Browse files
Log time in case of exception
1 parent e0ab809 commit e520144

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

Snowflake.Data/Core/RestRequester.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,29 +108,34 @@ protected virtual async Task<HttpResponseMessage> SendAsync(HttpRequestMessage m
108108
restRequestTimeout.Token))
109109
{
110110
HttpResponseMessage response = null;
111+
logger.Debug($"Executing: {sid} {message.Method} {message.RequestUri} HTTP/{message.Version}");
112+
var watch = new Stopwatch();
111113
try
112114
{
113-
logger.Debug($"Executing: {sid} {message.Method} {message.RequestUri} HTTP/{message.Version}");
114-
var watch = new Stopwatch();
115115
watch.Start();
116116
response = await _HttpClient
117117
.SendAsync(message, HttpCompletionOption.ResponseHeadersRead, linkedCts.Token)
118118
.ConfigureAwait(false);
119119
watch.Stop();
120120
if (!response.IsSuccessStatusCode)
121121
{
122-
logger.Error($"Failed Response after {watch.ElapsedMilliseconds} ms: {sid} {message.Method} {message.RequestUri} StatusCode: {(int)response.StatusCode}, ReasonPhrase: '{response.ReasonPhrase}'");
122+
logger.Error($"Failed response after {watch.ElapsedMilliseconds} ms: {sid} {message.Method} {message.RequestUri} StatusCode: {(int)response.StatusCode}, ReasonPhrase: '{response.ReasonPhrase}'");
123123
}
124124
else
125125
{
126-
logger.Debug($"Succeeded Response after {watch.ElapsedMilliseconds} ms: {sid} {message.Method} {message.RequestUri}");
126+
logger.Debug($"Succeeded response after {watch.ElapsedMilliseconds} ms: {sid} {message.Method} {message.RequestUri}");
127127
}
128128
response.EnsureSuccessStatusCode();
129129

130130
return response;
131131
}
132132
catch (Exception e)
133133
{
134+
if (watch.IsRunning)
135+
{
136+
watch.Stop();
137+
logger.Error($"Response receiving interrupted after {watch.ElapsedMilliseconds} ms by exception");
138+
}
134139
// Disposing of the response if not null now that we don't need it anymore
135140
response?.Dispose();
136141
if (restRequestTimeout.IsCancellationRequested)

0 commit comments

Comments
 (0)