< Summary

Information
Class: Chronicis.Api.Services.Open5eHealthCheckService
Assembly: Chronicis.Api
File(s): /home/runner/work/chronicis/chronicis/src/Chronicis.Api/Services/Open5eHealthCheckService.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 13
Coverable lines: 13
Total lines: 44
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 4
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%
PerformHealthCheckAsync()0%2040%

File(s)

/home/runner/work/chronicis/chronicis/src/Chronicis.Api/Services/Open5eHealthCheckService.cs

#LineLine coverage
 1using Chronicis.Shared.DTOs;
 2
 3namespace Chronicis.Api.Services;
 4
 5public class Open5eHealthCheckService : HealthCheckServiceBase
 6{
 7    private readonly HttpClient _httpClient;
 8    private readonly IConfiguration _configuration;
 9
 10    public Open5eHealthCheckService(
 11        HttpClient httpClient,
 12        IConfiguration configuration,
 13        ILogger<Open5eHealthCheckService> logger)
 014        : base(logger)
 15    {
 016        _httpClient = httpClient;
 017        _configuration = configuration;
 018    }
 19
 20    protected override async Task<(string Status, string? Message)> PerformHealthCheckAsync()
 21    {
 022        var baseUrl = _configuration["ExternalLinks:Open5e:BaseUrl"] ?? "https://api.open5e.com";
 23
 24        try
 25        {
 26            // Try a lightweight endpoint
 027            var testUrl = $"{baseUrl}/v2/monsters/?limit=1";
 028            var response = await _httpClient.GetAsync(testUrl);
 29
 030            if (response.IsSuccessStatusCode)
 31            {
 032                return (HealthStatus.Healthy, "Open5e API accessible");
 33            }
 34            else
 35            {
 036                return (HealthStatus.Degraded, $"Open5e API returned {response.StatusCode}");
 37            }
 38        }
 039        catch (Exception ex)
 40        {
 041            return (HealthStatus.Unhealthy, $"Open5e API error: {ex.Message}");
 42        }
 043    }
 44}