From 12c438f9f0b54c5ab82cb649341b5844a5443f2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20K=C3=BChnel?= Date: Tue, 26 Apr 2022 20:58:45 +0200 Subject: [PATCH] feat(GridService): log requestUri and error reason phrase --- SmartTeslaAmpSetter/Server/Services/GridService.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/SmartTeslaAmpSetter/Server/Services/GridService.cs b/SmartTeslaAmpSetter/Server/Services/GridService.cs index c81f579b5..2bfe2bdf6 100644 --- a/SmartTeslaAmpSetter/Server/Services/GridService.cs +++ b/SmartTeslaAmpSetter/Server/Services/GridService.cs @@ -21,10 +21,17 @@ public async Task GetCurrentOverage() _logger.LogTrace("{method}()", nameof(GetCurrentOverage)); using var httpClient = new HttpClient(); var requestUri = _configuration.GetValue("CurrentPowerToGridUrl"); + _logger.LogDebug("Using {uri} to get current overage.", requestUri); var response = await httpClient.GetAsync( requestUri) .ConfigureAwait(false); - response.EnsureSuccessStatusCode(); + + if (!response.IsSuccessStatusCode) + { + _logger.LogError("Could not get current overage. {statusCode}, {reasonPhrase}", response.StatusCode, response.ReasonPhrase); + response.EnsureSuccessStatusCode(); + } + var result = await response.Content.ReadAsStringAsync().ConfigureAwait(false); var jsonPattern = _configuration.GetValue("CurrentPowerToGridJsonPattern");