Basically, we're having an issue because part of the data returned when UrlCheck fails is different than the data returned when it is 200 OK. Especially, the URL is what we'd need.
In a simple report page we want to show something like the following, where I highlight where we have the issues.
A piece of data we'd like to show is the URL, in any case, even if it failed:
@model WebStatus.Viewmodels.HealthStatusViewModel
@{
ViewData["Title"] = "System Status";
}
<div class="row">
<div class="col-md-12">
<h2 class="overall-status-title">Overall Status: @Model.OverallStatus</h2>
</div>
</div>
<div class="list-group-status">
@foreach (var result in Model.Results)
{
<div class="row list-group-status-item">
<div class="col-md-10">
<h4 class="list-group-status-item-title">@result.Data["url"]</h4>
<p class="list-group-item-text">@result.Description</p>
</div>
<div class="col-md-2 list-group-status-item-label">
@if (@result.CheckStatus == Microsoft.Extensions.HealthChecks.CheckStatus.Healthy)
{
<span class="label label-success">@result.CheckStatus</span>
}
else if (@result.CheckStatus == Microsoft.Extensions.HealthChecks.CheckStatus.Unhealthy)
{
<span class="label label-danger">@result.CheckStatus</span>
}
else if (@result.CheckStatus == Microsoft.Extensions.HealthChecks.CheckStatus.Warning)
{
<span class="label label-warning">@result.CheckStatus</span>
}
else
{
<span class="label label-default">@result.CheckStatus</span>
}
</div>
</div>
}
</div>
But when returning the info about the healthCheck from the Library, I see the following:
public class UrlChecker
{
....
private async Task CheckUrlAsync(HttpClient httpClient, string url, Action<string, IHealthCheckResult> adder)
{
var name = $"UrlCheck({url})";
try
{
var response = await httpClient.GetAsync(url).ConfigureAwait(false);
var result = await _checkFunc(response);
adder(name, result);
}
catch (Exception ex)
{
adder(name, HealthCheckResult.Unhealthy($"Exception during check: {ex.GetType().FullName}"));
}
}
....
}
result, when the url check was 200 OK has more data, like the URL, etc., around 4 fields, but when HttpClient gets the exception, you are returning just the error without the URL, so it is not consistent with the same returned structure when it was successful. At least, I think the URL should be returned as part of the data. Don't you think so?
Would it be possible to return the same values or at least the URL which is always interesting to know about when the check fails or is unhealthy?
With the current approach, when trying to get the URL with @result.Data["url"]
we get an exception because it is, logically, null.
Thoughts?
Thanks for your help,
Cesar.