< Summary

Information
Class: MyNet.Http.Exceptions.WebApiException
Assembly: MyNet.Http
File(s): https://raw.githubusercontent.com/sandre58/MyNet/5aaaab311aa14541478b9e402357d98b657a23e4/src/MyNet.Http/Exceptions/WebApiException.cs
Tag: 342_31701152804
Line coverage
45%
Covered lines: 5
Uncovered lines: 6
Coverable lines: 11
Total lines: 74
Line coverage: 45.4%
Branch coverage
25%
Covered branches: 1
Total branches: 4
Branch coverage: 25%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%210%
.ctor(...)100%11100%
.ctor(...)100%210%
.ctor(...)100%210%
BuildMessage(...)25%44100%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/5aaaab311aa14541478b9e402357d98b657a23e4/src/MyNet.Http/Exceptions/WebApiException.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="WebApiException.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using System.Net;
 9
 10namespace MyNet.Http.Exceptions;
 11
 12/// <summary>
 13/// Represents an error returned by a web API.
 14/// </summary>
 15public class WebApiException : Exception
 16{
 17    /// <summary>
 18    /// Initializes a new instance of the <see cref="WebApiException"/> class.
 19    /// </summary>
 020    public WebApiException()
 21    {
 022    }
 23
 24    /// <summary>
 25    /// Initializes a new instance of the <see cref="WebApiException"/> class.
 26    /// </summary>
 27    /// <param name="statusCode">HTTP status code returned by the API.</param>
 28    /// <param name="reasonPhrase">HTTP reason phrase returned by the API.</param>
 29    /// <param name="responseBody">Raw response body.</param>
 30    /// <param name="payload">Parsed response payload when available.</param>
 31    public WebApiException(HttpStatusCode statusCode, string? reasonPhrase, string? responseBody, object? payload = null
 332        : base(BuildMessage(statusCode, reasonPhrase, responseBody, payload))
 33    {
 34        StatusCode = statusCode;
 35        ReasonPhrase = reasonPhrase;
 36        ResponseBody = responseBody;
 37        Payload = payload;
 338    }
 39
 40    /// <summary>
 41    /// Gets the HTTP status code returned by the API.
 42    /// </summary>
 43    public HttpStatusCode StatusCode { get; }
 44
 45    /// <summary>
 46    /// Gets the HTTP reason phrase returned by the API.
 47    /// </summary>
 48    public string? ReasonPhrase { get; }
 49
 50    /// <summary>
 51    /// Gets the raw response body returned by the API.
 52    /// </summary>
 53    public string? ResponseBody { get; }
 54
 55    /// <summary>
 56    /// Gets the parsed response payload when available.
 57    /// </summary>
 58    public object? Payload { get; }
 59
 60    protected WebApiException(string message)
 061        : base(message)
 62    {
 063    }
 64
 65    protected WebApiException(string message, Exception? innerException)
 066        : base(message, innerException)
 67    {
 068    }
 69
 370    private static string BuildMessage(HttpStatusCode statusCode, string? reasonPhrase, string? responseBody, object? pa
 371        ? $"HTTP {(int)statusCode} {reasonPhrase}: {responseBody}"
 372        : payload is not null ? $"HTTP {(int)statusCode} {reasonPhrase}: {payload}" : $"HTTP {(int)statusCode} {reasonPh
 73}
 74