< Summary

Information
Class: Syki.Shared.HttpExtensions
Assembly: Shared
File(s): /home/runner/work/syki/syki/Shared/Extensions/HttpExtensions.cs
Tag: 22_11348620282
Line coverage
100%
Covered lines: 12
Uncovered lines: 0
Coverable lines: 12
Total lines: 30
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ToError()100%11100%
DeserializeTo()100%11100%
Resolve()100%44100%

File(s)

/home/runner/work/syki/syki/Shared/Extensions/HttpExtensions.cs

#LineLine coverage
 1using System.Net;
 2using Newtonsoft.Json;
 3
 4namespace Syki.Shared;
 5
 6public static class HttpExtensions
 7{
 8    public static async Task<ErrorOut> ToError(this HttpResponseMessage httpResponse)
 9    {
 12310        var responseAsString = await httpResponse.Content.ReadAsStringAsync();
 12311        return JsonConvert.DeserializeObject<ErrorOut>(responseAsString)!;
 12312    }
 13
 14    public static async Task<T> DeserializeTo<T>(this HttpResponseMessage httpResponse)
 15    {
 383216        var responseAsString = await httpResponse.Content.ReadAsStringAsync();
 383217        return JsonConvert.DeserializeObject<T>(responseAsString)!;
 383218    }
 19
 20    public static async Task<OneOf<T, ErrorOut>> Resolve<T>(this HttpResponseMessage httpResponse)
 21    {
 197622        if (httpResponse.IsSuccessStatusCode)
 185123            return await httpResponse.DeserializeTo<T>();
 24
 12525        if (httpResponse.StatusCode == HttpStatusCode.Forbidden)
 226            return new ForbiddenErrorOut();
 27
 12328        return await httpResponse.ToError();
 197629    }
 30}

Methods/Properties

ToError()
DeserializeTo()
Resolve()