< Summary

Information
Class: event_list.shared.Middlewares.ExceptionMiddleware
Assembly: event-list
File(s): /Users/tiagoamaral/Workspace/desafio/event-list-api/Src/Shared/Middlewares/ExceptionMiddleware.cs
Line coverage
100%
Covered lines: 15
Uncovered lines: 0
Coverable lines: 15
Total lines: 40
Line coverage: 100%
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%
InvokeAsync()100%11100%

File(s)

/Users/tiagoamaral/Workspace/desafio/event-list-api/Src/Shared/Middlewares/ExceptionMiddleware.cs

#LineLine coverage
 1/*
 2* ExceptionMiddleware.cs
 3* event-list
 4*
 5* Created by Tiago Amaral on 06/09/2025.
 6* Copyright ©2024 Tiago Amaral. All rights reserved.
 7*/
 8
 9using System.Text.Json;
 10using event_list.shared.response_default;
 11using event_list.shared.exceptionsMessage;
 12using Microsoft.AspNetCore.Http;
 13
 14namespace event_list.shared.Middlewares;
 15
 16public class ExceptionMiddleware
 17{
 18    private readonly RequestDelegate _next;
 19
 220    public ExceptionMiddleware(RequestDelegate next)
 221    {
 222        _next = next;
 223    }
 24
 25    public async Task InvokeAsync(HttpContext context)
 226    {
 27        try
 228        {
 229            await _next(context);
 130        }
 131        catch (Exception ex)
 132        {
 33            // Internal log
 34            // Console.WriteLine( ex.GetType());
 135            var responseDefault = new ResponseDefault(context.Response.StatusCode, ex.Message, null);
 136            context.Response.ContentType = "application/json";
 137            await context.Response.WriteAsync(JsonSerializer.Serialize(responseDefault));
 138        }
 239    }
 40}