HttpFaultResolver Class
Definition
- Namespace
- Cuemon.AspNetCore.Diagnostics
- Assemblies
- Cuemon.AspNetCore.dll
Provides a way to evaluate an exception and provide details about it in a developer friendly way, optimized for open- and otherwise public application programming interfaces (API).
public class HttpFaultResolver : FaultHandler<HttpExceptionDescriptor>
- Inheritance
-
HttpFaultResolver
- Inherited Members
Examples
The following example demonstrates how to create an HTTP fault resolver that maps exceptions to HTTP error responses.
using System;
using Cuemon.AspNetCore.Diagnostics;
using Cuemon.Diagnostics;
namespace MyApp.Examples;
public class HttpFaultResolverExample
{
public void Demonstrate()
{
var resolver = new HttpFaultResolver(
exception => exception is ArgumentNullException,
exception => new HttpExceptionDescriptor(exception, 400, null, "Argument was null."));
if (resolver.TryResolveFault(new ArgumentNullException("value"), out var descriptor))
{
Console.WriteLine(descriptor.StatusCode); // 400
}
var resolved = resolver.TryResolveFault(new InvalidOperationException(), out _);
Console.WriteLine(resolved); // False
}
}
Constructors
| Name | Description |
|---|---|
| HttpFaultResolver(Func<Exception, bool>, Func<Exception, HttpExceptionDescriptor>) | Initializes a new instance of the HttpFaultResolver class. |