Documentation Index
Fetch the complete documentation index at: https://mintlify.com/FloppyShelf/Problemize/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Problemize implements centralized exception handling through theExceptionHandler class, which integrates seamlessly with ASP.NET Core’s global exception handling pipeline. This approach ensures that all unhandled exceptions in your Web API are converted into standardized Problem Details responses.
How it works
TheExceptionHandler class implements ASP.NET Core’s IExceptionHandler interface, making it part of the framework’s built-in exception handling middleware.
Core architecture
The handler depends on two key components:Services/ExceptionHandler.cs
IProblemDetailsService is ASP.NET Core’s built-in service for writing Problem Details responses, while IStatusCodeMapper is Problemize’s interface for mapping exceptions to HTTP status codes.Exception processing flow
When an unhandled exception occurs, theTryHandleAsync method executes the following steps:
1. Map exception to status code
Services/ExceptionHandler.cs
2. Create problem details context
Services/ExceptionHandler.cs
3. Build the problem details object
The handler creates different problem details objects based on the exception type:Services/ExceptionHandler.cs
ValidationException instances receive special handling with ValidationProblemDetails, which supports structured validation error responses.4. Write the response
Services/ExceptionHandler.cs
IProblemDetailsService serializes the problem details object and writes it to the HTTP response, applying any customizations configured in your application.
Registration
The exception handler is automatically registered when you callUseExceptionHandling:
Configurator.cs
Key benefits
- Automatic conversion: All exceptions are automatically converted to Problem Details format
- Type-aware handling: Different exception types receive appropriate status codes and response formats
- Pipeline integration: Works seamlessly with ASP.NET Core’s exception handling middleware
- Extensible: The status code mapper can be customized for application-specific exception types
Related concepts
- Status code mapping - Learn how exceptions are mapped to HTTP status codes
- Problem details - Understand the structure of Problem Details responses