Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

README.md

ErrorMiddlewareExample - ASP.NET Core Exception Handling Middleware and Standardized API Responses

YouTube Blog Newsletter All Links LinkedIn

This project demonstrates how to implement centralized exception handling middleware in ASP.NET Core using .NET 8.0. It showcases the use of UseExceptionHandler() to intercept unhandled exceptions globally and map them to standardized API responses. The project includes a custom ValidationException type, a standardized ApiResponse record with Data and Error properties, and an IEndpointFilter implementation that wraps all endpoint results in a consistent response format.

The solution also demonstrates how to combine global exception handling with endpoint-level filtering for consistent API responses. FluentValidation is integrated for input validation, and Swagger/OpenAPI documentation is included via Swashbuckle. The project provides conditional debug information, including stack traces in DEBUG builds, while keeping production responses clean. This is a practical reference for building robust, production-ready ASP.NET Core APIs with proper error handling.

Getting Started

Prerequisites

  • .NET 8.0 SDK or later

Running the Project

cd ErrorMiddlewareExample
dotnet run

Related Resources

Blog Articles

YouTube Videos

Newsletter

If you found this useful and you want to learn more about C#, .NET, and software engineering, subscribe to the free Dev Leader Weekly newsletter:

Subscribe to Dev Leader Weekly

Connect with Dev Leader


BrandGhost

Powered by BrandGhost 👻