< 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
0%
Covered lines: 0
Uncovered lines: 27
Coverable lines: 27
Total lines: 63
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
GetSystemHealthAsync()0%620%

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
 015    public HealthStatusApiService(HttpClient httpClient, ILogger<HealthStatusApiService> logger)
 16    {
 017        _httpClient = httpClient;
 018        _logger = logger;
 019    }
 20
 21    public async Task<SystemHealthStatusDto?> GetSystemHealthAsync()
 22    {
 23        try
 24        {
 025            _logger.LogInformation("Requesting health status from /health/status");
 026            var response = await _httpClient.GetAsync("/health/status");
 27
 028            _logger.LogInformation("Health status API returned {StatusCode}", response.StatusCode);
 29
 030            if (response.IsSuccessStatusCode)
 31            {
 032                var content = await response.Content.ReadAsStringAsync();
 033                _logger.LogDebug("Health status response: {Content}", content);
 34
 035                return System.Text.Json.JsonSerializer.Deserialize<SystemHealthStatusDto>(content, new System.Text.Json.
 036                {
 037                    PropertyNameCaseInsensitive = true
 038                });
 39            }
 40            else
 41            {
 042                var errorContent = await response.Content.ReadAsStringAsync();
 043                _logger.LogWarning("Health status API returned {StatusCode}: {ErrorContent}", response.StatusCode, error
 044                return null;
 45            }
 46        }
 047        catch (HttpRequestException httpEx)
 48        {
 049            _logger.LogError(httpEx, "HTTP error while fetching system health status");
 050            return null;
 51        }
 052        catch (TaskCanceledException tcEx)
 53        {
 054            _logger.LogError(tcEx, "Timeout while fetching system health status");
 055            return null;
 56        }
 057        catch (Exception ex)
 58        {
 059            _logger.LogError(ex, "Failed to fetch system health status");
 060            return null;
 61        }
 062    }
 63}