< Summary - ZhEaIsNsAaBn.Libraries coverage (affected: 23 packages)

Information
Class: ZhEaIsNsAaBn.Utilities.APIExceptionHandlers.ExternalServiceExceptionHandler
Assembly: ZhEaIsNsAaBn.Utilities.APIExceptionHandlers
File(s): /home/runner/work/ZhEaIsNsAaBn.Libraries.V1/ZhEaIsNsAaBn.Libraries.V1/src/UtilitiesPackages/ZhEaIsNsAaBn.Utilities.APIExceptionHandlers/GlobalHandlers/ExternalServiceExceptionHandler.cs
Line coverage
100%
Covered lines: 16
Uncovered lines: 0
Coverable lines: 16
Total lines: 48
Line coverage: 100%
Branch coverage
87%
Covered branches: 7
Total branches: 8
Branch coverage: 87.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
TryHandleAsync()87.5%88100%

File(s)

/home/runner/work/ZhEaIsNsAaBn.Libraries.V1/ZhEaIsNsAaBn.Libraries.V1/src/UtilitiesPackages/ZhEaIsNsAaBn.Utilities.APIExceptionHandlers/GlobalHandlers/ExternalServiceExceptionHandler.cs

#LineLine coverage
 1using Microsoft.Extensions.Options;
 2
 3namespace ZhEaIsNsAaBn.Utilities.APIExceptionHandlers;
 4
 5/// <summary>
 6/// Handles failed calls to other services: <see cref="HttpRequestException"/> → <c>BadGateway</c> (default 502),
 7/// <see cref="TaskCanceledException"/> (a timeout) → <c>GatewayTimeout</c> (default 504). Category: <c>ExternalService<
 8/// A request the client aborted never gets here: ASP.NET Core's exception middleware answers 499 itself.
 9/// </summary>
 10public sealed class ExternalServiceExceptionHandler : BaseExceptionHandler<ExternalServiceExceptionHandler>, IExceptionH
 11{
 12    private const string Category = "ExternalService";
 13
 14
 15    /// <summary>Creates the handler.</summary>
 16    /// <param name="logger">The logger.</param>
 17    /// <param name="environment">The host environment; Development adds the HTTP error text.</param>
 18    /// <param name="settings">The status mapping.</param>
 19    public ExternalServiceExceptionHandler( ILogger<ExternalServiceExceptionHandler> logger, IWebHostEnvironment environ
 19220        : base( logger, environment, settings ) { }
 21
 22
 23    /// <inheritdoc />
 24    public async ValueTask<bool> TryHandleAsync( HttpContext httpContext, Exception exception, CancellationToken cancell
 25    {
 6426        ArgumentNullException.ThrowIfNull( httpContext );
 27
 6428        Error? error = exception switch
 6429                           {
 830                               HttpRequestException http => new Error( "BadGateway", Category, "خدمة خارجية غير متاحة حا
 831                                                                       "An external service is currently unavailable. Pl
 832                                                                       + ( Environment.IsDevelopment() ? $" HTTP Error: 
 433                               TaskCanceledException => new Error( "GatewayTimeout", Category, "انتهت مهلة الطلب أثناء ا
 434                                                                   "The request timed out while waiting for an external 
 5235                               _ => null
 6436                           };
 37
 11638        if ( error is null ) { return false; }
 39
 40
 1241        Log.ExternalServiceError( Logger, exception, httpContext.Request.Path, httpContext.Request.Method, httpContext.T
 42
 43
 1244        await GenerateError( httpContext, error, cancellationToken ).ConfigureAwait( false );
 45
 1246        return true;
 6447    }
 48}