Xabaril / AspNetCore.Diagnostics.HealthChecks

Enterprise HealthChecks for ASP.NET Core Diagnostics Package
Apache License 2.0
3.98k stars 770 forks source link

Issue with HealthCheck URI returning 404 error code #2218

Open JimPShaw opened 1 month ago

JimPShaw commented 1 month ago

.Net core 8, in chrome browser.

In HealthCheckReportCollector, the code which interprets the response from health check endpoint does not handle 404 (or any error http response code properly)

The code in method GetHealthReportAsync(...) has the following code: if (!response.IsSuccessStatusCode && response.Content.Headers.ContentType?.MediaType != "application/json")

So getting a 404 error http response, with content type of 'application/json' never gets reported in DB as an error. It creates an UIHealthReport object with Status of '404' instead of 'Healthy', 'Unhealthy', etc...

As a result, the UI crashes in its javascript, it can't interpret dcolour code for a status of '404'.

JimPShaw commented 1 month ago

Essentially I can solve the issue, if I download the source code and change the AND to an OR. As long as it has an unsuccessful response it should be logged as an error, regardless of the content type being 'application/json'.