< Summary

Information
Class: LGDXRobotCloud.API.Middleware.LgdxExpectionHandlingMiddlewareExtensions
Assembly: LGDXRobotCloud.API
File(s): /builds/yukaitung/lgdxrobot2-cloud/LGDXRobotCloud.API/Middleware/LgdxExpectionHandlingMiddleware.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 3
Coverable lines: 3
Total lines: 36
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
UseLgdxExpectionHandling(...)100%210%

File(s)

/builds/yukaitung/lgdxrobot2-cloud/LGDXRobotCloud.API/Middleware/LgdxExpectionHandlingMiddleware.cs

#LineLine coverage
 1using LGDXRobotCloud.API.Exceptions;
 2namespace LGDXRobotCloud.API.Middleware;
 3
 4public class LgdxExpectionHandlingMiddleware(RequestDelegate next)
 5{
 6  private readonly RequestDelegate _next = next;
 7
 8  public async Task InvokeAsync(HttpContext context)
 9  {
 10    try
 11    {
 12      await _next(context);
 13    }
 14    catch (Exception ex)
 15    {
 16      if (ex is ILgdxExceptionBase casted)
 17      {
 18        await HandleExceptionAsync(context, casted);
 19      }
 20      else throw;
 21    }
 22  }
 23
 24  private static async Task HandleExceptionAsync(HttpContext context, ILgdxExceptionBase ex)
 25  {
 26    await ex.HandleExceptionAsync(context);
 27  }
 28}
 29
 30public static class LgdxExpectionHandlingMiddlewareExtensions
 31{
 32  public static IApplicationBuilder UseLgdxExpectionHandling(this IApplicationBuilder builder)
 033  {
 034    return builder.UseMiddleware<LgdxExpectionHandlingMiddleware>();
 035  }
 36}