< Summary

Information
Class: Chronicis.Client.Services.HealthStatusApiService
Assembly: Chronicis.Client
File(s): /home/runner/work/chronicis/chronicis/src/Chronicis.Client/Services/IHealthStatusApiService.cs
Line coverage
100%
Covered lines: 3
Uncovered lines: 0
Coverable lines: 3
Total lines: 63
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%

File(s)

/home/runner/work/chronicis/chronicis/src/Chronicis.Client/Services/IHealthStatusApiService.cs

#LineLine coverage
 1using Chronicis.Shared.DTOs;
 2
 3namespace Chronicis.Client.Services;
 4
 5public interface IHealthStatusApiService
 6{
 7    Task<SystemHealthStatusDto?> GetSystemHealthAsync();
 8}
 9
 10public class HealthStatusApiService : IHealthStatusApiService
 11{
 12    private readonly HttpClient _httpClient;
 13    private readonly ILogger<HealthStatusApiService> _logger;
 14
 15    public HealthStatusApiService(HttpClient httpClient, ILogger<HealthStatusApiService> logger)
 16    {
 617        _httpClient = httpClient;
 618        _logger = logger;
 619    }
 20
 21    public async Task<SystemHealthStatusDto?> GetSystemHealthAsync()
 22    {
 23        try
 24        {
 25            _logger.LogInformation("Requesting health status from /health/status");
 26            var response = await _httpClient.GetAsync("/health/status");
 27
 28            _logger.LogInformation("Health status API returned {StatusCode}", response.StatusCode);
 29
 30            if (response.IsSuccessStatusCode)
 31            {
 32                var content = await response.Content.ReadAsStringAsync();
 33                _logger.LogDebug("Health status response: {Content}", content);
 34
 35                return System.Text.Json.JsonSerializer.Deserialize<SystemHealthStatusDto>(content, new System.Text.Json.
 36                {
 37                    PropertyNameCaseInsensitive = true
 38                });
 39            }
 40            else
 41            {
 42                var errorContent = await response.Content.ReadAsStringAsync();
 43                _logger.LogWarning("Health status API returned {StatusCode}: {ErrorContent}", response.StatusCode, error
 44                return null;
 45            }
 46        }
 47        catch (HttpRequestException httpEx)
 48        {
 49            _logger.LogError(httpEx, "HTTP error while fetching system health status");
 50            return null;
 51        }
 52        catch (TaskCanceledException tcEx)
 53        {
 54            _logger.LogError(tcEx, "Timeout while fetching system health status");
 55            return null;
 56        }
 57        catch (Exception ex)
 58        {
 59            _logger.LogError(ex, "Failed to fetch system health status");
 60            return null;
 61        }
 62    }
 63}