Table of Contents

Class FaultDescriptorOptionsDecoratorExtensions

Namespace
Cuemon.AspNetCore.Diagnostics
Assembly
Cuemon.AspNetCore.dll

Extension methods for FaultDescriptorOptions class hidden behind the IDecorator<T> interface.

public static class FaultDescriptorOptionsDecoratorExtensions
Inheritance
FaultDescriptorOptionsDecoratorExtensions

Examples

FaultDescriptorOptionsDecoratorExtensions provides extension methods on Decorator.Enclose for resolving HTTP exception descriptors from failure objects using FaultDescriptorOptions. This example creates a FaultDescriptorOptions instance and a BadRequestException as the failure input, then wraps the options with Decorator.Enclose and calls TryResolveHttpExceptionDescriptor with the failure and an HttpContext. The resolved descriptor's StatusCode is output as 400, confirming the failure was correctly mapped to a Bad Request HTTP response.

using System;
using Cuemon;
using Cuemon.AspNetCore.Diagnostics;
using Cuemon.AspNetCore.Http;
using Microsoft.AspNetCore.Http;

namespace MyApp.Examples;

public class FaultDescriptorOptionsDecoratorExtensionsExample
{
    public void Demonstrate(HttpContext context)
    {
        var options = new FaultDescriptorOptions();
        var failure = new BadRequestException("Bad request");
        Decorator.Enclose(options).TryResolveHttpExceptionDescriptor(
            failure,
            context,
            descriptor => Console.WriteLine("Resolved descriptor"),
            out var descriptor);
        Console.WriteLine(descriptor.StatusCode); // 400
    }
}

Methods

TryResolveHttpExceptionDescriptor<T>(IDecorator<T>, Exception, HttpContext, Action<HttpExceptionDescriptor>, out HttpExceptionDescriptor)

Tries to resolve an HttpExceptionDescriptor from the specified failure and context.

public static bool TryResolveHttpExceptionDescriptor<T>(this IDecorator<T> decorator, Exception failure, HttpContext context, Action<HttpExceptionDescriptor> onBeforeExceptionFactory, out HttpExceptionDescriptor descriptor) where T : FaultDescriptorOptions

Parameters

decorator IDecorator<T>

The decorator that encapsulates the FaultDescriptorOptions.

failure Exception

The Exception that represents the failure.

context HttpContext

The HttpContext in which the failure occurred.

onBeforeExceptionFactory Action<HttpExceptionDescriptor>

A delegate to invoke just before the ExceptionCallback is called.

descriptor HttpExceptionDescriptor

When this method returns, contains the resolved HttpExceptionDescriptor, if the resolution succeeded, or null if the resolution failed.

Returns

bool

true if the HttpExceptionDescriptor was resolved successfully; otherwise, false.

Type Parameters

T

The type of the FaultDescriptorOptions.

Exceptions

ArgumentNullException

decorator cannot be null -or- failure cannot be null -or- context cannot be null.