Class HttpExceptionDescriptorDecoratorExtensions
- Namespace
- Cuemon.AspNetCore.Diagnostics
- Assembly
- Cuemon.AspNetCore.dll
Extension methods for HttpExceptionDescriptor class hidden behind the IDecorator<T> interface.
public static class HttpExceptionDescriptorDecoratorExtensions
- Inheritance
-
HttpExceptionDescriptorDecoratorExtensions
Examples
HttpExceptionDescriptorDecoratorExtensions provides extension methods on Decorator.Enclose for converting HttpExceptionDescriptor instances into ASP.NET Core ProblemDetails objects for structured API error responses. This example creates an HttpExceptionDescriptor from a BadRequestException with CorrelationId, RequestId, and TraceId set as context, then wraps it with Decorator.Enclose and calls ToProblemDetails with FaultSensitivityDetails.None. The resulting ProblemDetails.Title is printed to the console, showing the error output ready for serialization into an HTTP API response body.
using System;
using Cuemon;
using Cuemon.AspNetCore.Http;
using Cuemon.Diagnostics;
using Microsoft.AspNetCore.Mvc;
namespace Cuemon.AspNetCore.Diagnostics;
public static class HttpExceptionDescriptorDecoratorExtensionsExample
{
public static void Demonstrate()
{
var descriptor = new HttpExceptionDescriptor(new BadRequestException())
{
CorrelationId = "corr-42",
RequestId = "req-42",
TraceId = "trace-42"
};
ProblemDetails problem = Decorator.Enclose(descriptor).ToProblemDetails(FaultSensitivityDetails.None);
Console.WriteLine(problem.Title);
}
}
Methods
ToProblemDetails(IDecorator<HttpExceptionDescriptor>, FaultSensitivityDetails)
Converts the specified IDecorator<T> of HttpExceptionDescriptor to an instance of ProblemDetails.
public static ProblemDetails ToProblemDetails(this IDecorator<HttpExceptionDescriptor> decorator, FaultSensitivityDetails sensitivity)
Parameters
decoratorIDecorator<HttpExceptionDescriptor>The decorator that encapsulates the HttpExceptionDescriptor.
sensitivityFaultSensitivityDetailsThe sensitivity details to include in the ProblemDetails.
Returns
- ProblemDetails
An instance of ProblemDetails that represents the specified HttpExceptionDescriptor.
Exceptions
- ArgumentNullException
decoratorcannot be null.