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
Status code mapping is the process of converting exception types into semantically correct HTTP status codes. Problemize provides a default implementation that handles common .NET exception types, and allows you to provide custom mapping logic for your application-specific exceptions.The IStatusCodeMapper interface
TheIStatusCodeMapper interface defines a simple contract for mapping exceptions to status codes:
Interfaces/IStatusCodeMapper.cs
Default implementation
Problemize includes aStatusCodeMapper class that maps common .NET framework exceptions to appropriate HTTP status codes using a switch expression:
Services/StatusCodeMapper.cs
Mapping categories
The default mapper organizes exceptions into semantic HTTP status code categories:Client errors (4xx)
Bad Request (400)
Bad Request (400)
Used for validation and argument errors:
ArgumentNullExceptionArgumentOutOfRangeExceptionInvalidOperationExceptionValidationExceptionFormatExceptionOverflowExceptionNullReferenceException
Unauthorized (401)
Unauthorized (401)
Not Found (404)
Not Found (404)
Used when resources cannot be located:
KeyNotFoundExceptionFileNotFoundExceptionDirectoryNotFoundException
Method Not Allowed (405)
Method Not Allowed (405)
Used for unsupported operations:
NotSupportedException
Request Timeout (408)
Request Timeout (408)
Used for timeout scenarios:
TimeoutException
Server errors (5xx)
Internal Server Error (500)
Internal Server Error (500)
Used for critical runtime errors and any unmapped exception:
OutOfMemoryExceptionStackOverflowException- Any other exception (default case)
Not Implemented (501)
Not Implemented (501)
Used for unimplemented functionality:
NotImplementedException
Custom status code mapping
You can provide a custom implementation ofIStatusCodeMapper to handle application-specific exceptions:
Registering a custom mapper
Pass your custom mapper to theUseExceptionHandling method:
Configurator.cs
The status code mapper is registered as a singleton, so it should be stateless and thread-safe.
How it integrates
The status code mapper is called early in the exception handling process:- An exception occurs in your API
- The
ExceptionHandlerreceives the exception - The
IStatusCodeMapper.GetStatusCode()method is invoked - The returned status code is set on the HTTP response
- The Problem Details object is created and returned
Services/ExceptionHandler.cs
Related concepts
- Exception handling - Learn how the exception handler uses the status code mapper
- Problem details - Understand the response format returned to clients