< Summary

Information
Class: Syki.Back.Exceptions.ExceptionsMiddleware
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Exceptions/ExceptionsMiddleware.cs
Tag: 22_11348620282
Line coverage
36%
Covered lines: 4
Uncovered lines: 7
Coverable lines: 11
Total lines: 31
Line coverage: 36.3%
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
.ctor(...)100%11100%
Invoke()100%1.06160%
HandleExceptionAsync(...)100%210%

File(s)

/home/runner/work/syki/syki/Back/Exceptions/ExceptionsMiddleware.cs

#LineLine coverage
 1using System.Text.Json;
 2using ILogger = Serilog.ILogger;
 3
 4namespace Syki.Back.Exceptions;
 5
 16public class ExceptionsMiddleware(RequestDelegate next, ILogger logger)
 7{
 8    public async Task Invoke(HttpContext context)
 9    {
 10        try
 11        {
 495712            await next(context);
 495713        }
 014        catch (Exception ex)
 15        {
 016            await HandleExceptionAsync(context, ex);
 17        }
 495718    }
 19
 20    private Task HandleExceptionAsync(HttpContext context, Exception ex)
 21    {
 022        var result = JsonSerializer.Serialize(new ErrorOut { Message = "Internal Server Error" });
 23
 024        context.Response.ContentType = "application/json";
 025        context.Response.StatusCode = 500;
 26
 027        logger.Error("Internal Server Error -> {Message}", ex.Message);
 28
 029        return context.Response.WriteAsync(result);
 30    }
 31}