< Summary

Information
Class: MyNet.Http.Exceptions.MultipleHttpException
Assembly: MyNet.Http
File(s): https://raw.githubusercontent.com/sandre58/MyNet/5aaaab311aa14541478b9e402357d98b657a23e4/src/MyNet.Http/Exceptions/MultipleHttpException.cs
Tag: 342_31701152804
Line coverage
66%
Covered lines: 14
Uncovered lines: 7
Coverable lines: 21
Total lines: 143
Line coverage: 66.6%
Branch coverage
75%
Covered branches: 3
Total branches: 4
Branch coverage: 75%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%1150%
get_Errors()100%11100%
.ctor(...)100%210%
.ctor(...)100%210%
.ctor(...)100%11100%
.ctor(...)100%11100%
.ctor(...)100%11100%
.ctor(...)100%210%
ToString()75%44100%

File(s)

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

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="MultipleHttpException.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using System.Collections.Generic;
 9using System.Globalization;
 10using System.Linq;
 11using System.Text;
 12
 13namespace MyNet.Http.Exceptions;
 14
 15/// <summary>
 16/// Represents an exception that encapsulates multiple HTTP errors, allowing for comprehensive error reporting in scenar
 17/// </summary>
 18public class MultipleHttpException : Exception
 19{
 1220    private readonly List<HttpError> _errors = [];
 21
 22    /// <summary>
 23    /// Gets a read-only collection of <see cref="HttpError"/> instances that represent the individual errors associated
 24    /// </summary>
 1825    public IReadOnlyCollection<HttpError> Errors => _errors.AsReadOnly();
 26
 27    /// <summary>
 28    /// Initializes a new instance of the <see cref="MultipleHttpException"/> class with no parameters. This constructor
 29    /// </summary>
 030    public MultipleHttpException() { }
 31
 32    /// <summary>
 33    /// Initializes a new instance of the <see cref="MultipleHttpException"/> class with a specified error message. This
 34    /// </summary>
 35    /// <param name="message">The error message that explains the reason for the exception.</param>
 36    public MultipleHttpException(string message)
 037        : base(message)
 38    {
 039    }
 40
 41    /// <summary>
 42    /// Initializes a new instance of the <see cref="MultipleHttpException"/> class with a collection of error messages.
 43    /// </summary>
 44    /// <param name="errors">A collection of error messages that describe the individual errors.</param>
 45    public MultipleHttpException(IEnumerable<string> errors)
 046        : this(string.Empty, errors)
 47    {
 048    }
 49
 50    /// <summary>
 51    /// Initializes a new instance of the <see cref="MultipleHttpException"/> class with a collection of <see cref="Http
 52    /// </summary>
 53    /// <param name="errors">A collection of <see cref="HttpError"/> instances that describe the individual errors.</par
 54    public MultipleHttpException(IEnumerable<HttpError> errors)
 355        : this(string.Empty, errors)
 56    {
 357    }
 58
 59    /// <summary>
 60    /// Initializes a new instance of the <see cref="MultipleHttpException"/> class with a specified error message and a
 61    /// </summary>
 62    /// <param name="message">The error message that explains the reason for the exception.</param>
 63    /// <param name="errors">A collection of <see cref="HttpError"/> instances that describe the individual errors.</par
 64    public MultipleHttpException(string message, IEnumerable<HttpError> errors)
 965        : base(message)
 966        => _errors.AddRange(errors);
 67
 68    /// <summary>
 69    /// Initializes a new instance of the <see cref="MultipleHttpException"/> class with a specified error message and a
 70    /// </summary>
 71    /// <param name="message">The error message that explains the reason for the exception.</param>
 72    /// <param name="errors">A collection of error messages that describe the individual errors.</param>
 73    public MultipleHttpException(string message, IEnumerable<string> errors)
 374        : base(message)
 375        => _errors.AddRange(errors.Select(x => new HttpError(x)));
 76
 77    /// <summary>
 78    /// Initializes a new instance of the <see cref="MultipleHttpException"/> class with a specified error message and a
 79    /// </summary>
 80    /// <param name="message">The error message that explains the reason for the exception.</param>
 81    /// <param name="exception">The exception that is the cause of the current exception.</param>
 82    public MultipleHttpException(string message, Exception exception)
 083        : base(message, exception)
 84    {
 085    }
 86
 87    /// <summary>
 88    /// Returns a string that represents the current exception, including the main error message and the details of each
 89    /// </summary>
 90    /// <returns>A string representation of the current exception.</returns>
 91    public override string ToString()
 92    {
 393        var errorMessage = new StringBuilder();
 94
 395        if (!string.IsNullOrEmpty(Message))
 96        {
 397            _ = errorMessage.AppendLine(Message);
 98        }
 99
 18100        foreach (var error in Errors)
 101        {
 6102            _ = errorMessage.AppendLine(CultureInfo.CurrentCulture, $" - {error.Message}");
 103        }
 104
 3105        return errorMessage.ToString();
 106    }
 107}
 108
 109/// <summary>
 110/// Represents an individual HTTP error, encapsulating a message and an optional code that provides specific details abo
 111/// </summary>
 112public class HttpError
 113{
 114    /// <summary>
 115    /// Gets the error message that describes the specific issue that occurred during an HTTP operation. This property p
 116    /// </summary>
 117    public string Message { get; }
 118
 119    /// <summary>
 120    /// Gets an optional code that provides additional information about the specific error that occurred during an HTTP
 121    /// </summary>
 122    public string? Code { get; }
 123
 124    /// <summary>
 125    /// Initializes a new instance of the <see cref="HttpError"/> class with a specified error code and message. This co
 126    /// </summary>
 127    /// <param name="code">The error code that categorizes the error.</param>
 128    /// <param name="message">The error message that describes the specific issue.</param>
 129    public HttpError(string code, string message) => (Code, Message) = (code, message);
 130
 131    /// <summary>
 132    /// Initializes a new instance of the <see cref="HttpError"/> class with a specified error message. This constructor
 133    /// </summary>
 134    /// <param name="message">The error message that describes the specific issue.</param>
 135    public HttpError(string message) => Message = message;
 136
 137    /// <summary>
 138    /// Returns a string that represents the current error, which is the error message. This method provides a simple wa
 139    /// </summary>
 140    /// <returns>A string that represents the current error.</returns>
 141    public override string ToString() => Message;
 142}
 143