From 7d09f94b98ae9471ceba6eb7c98ac5189ec396a4 Mon Sep 17 00:00:00 2001 From: Ivan Maximov Date: Sun, 30 Jul 2023 14:38:39 +0300 Subject: [PATCH] Handle not OK HTTP status codes in HealthCheckReportCollector (#1963) --- .../Core/HostedService/HealthCheckReportCollector.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/HealthChecks.UI/Core/HostedService/HealthCheckReportCollector.cs b/src/HealthChecks.UI/Core/HostedService/HealthCheckReportCollector.cs index 55a09578f8..923ea21480 100644 --- a/src/HealthChecks.UI/Core/HostedService/HealthCheckReportCollector.cs +++ b/src/HealthChecks.UI/Core/HostedService/HealthCheckReportCollector.cs @@ -143,6 +143,9 @@ private async Task GetHealthReportAsync(HealthCheckConfiguration using (response) { + if (!response.IsSuccessStatusCode) + return UIHealthReport.CreateFrom(new InvalidOperationException($"HTTP response is not in valid state ({response.StatusCode}) when trying to get report from {uri} configured with name {name}.")); + return await response.Content.ReadFromJsonAsync(_options) ?? throw new InvalidOperationException($"{nameof(HttpContentJsonExtensions.ReadFromJsonAsync)} returned null"); }