Table of Contents

HttpFaultResolverDecoratorExtensions Class

Definition

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

public static class HttpFaultResolverDecoratorExtensions
Inheritance
HttpFaultResolverDecoratorExtensions

Examples

The following example demonstrates how to register fault resolvers using the decorator pattern over a list of HttpFaultResolver.

using System;
using System.Collections.Generic;
using Cuemon.AspNetCore.Diagnostics;
using Cuemon.AspNetCore.Http;

using Cuemon;
namespace Examples;

public class FaultResolverRegistrationExample
{
    public IList<HttpFaultResolver> RegisterResolvers()
    {
        var resolvers = new List<HttpFaultResolver>();

        // Add a resolver for NotFoundException (404)
        Decorator.Enclose(resolvers).AddHttpFaultResolver<NotFoundException>(
            message: "The requested resource was not found.",
            helpLink: new Uri("https://example.com/errors/404"));

        // Add a resolver for UnauthorizedException (401) with a custom code
        Decorator.Enclose(resolvers).AddHttpFaultResolver<UnauthorizedException>(
            statusCode: 401,
            code: "UNAUTHORIZED",
            message: "Authentication is required.");

        return resolvers;

}
}

Methods

Name Description
AddHttpFaultResolver<T>(IDecorator<IList<HttpFaultResolver>>, Func<T, HttpExceptionDescriptor>, Func<Exception, bool>)

Adds the specified function delegate exceptionDescriptorResolver and function delegate exceptionValidator to the enclosed IList<T> of the decorator.

AddHttpFaultResolver<T>(IDecorator<IList<HttpFaultResolver>>, int, string, string, Uri, Func<Exception, bool>)

Adds a new HttpExceptionDescriptor to the enclosed IList<T> of the decorator from the parameters provided.

AddHttpFaultResolver<T>(IDecorator<IList<HttpFaultResolver>>, string, Uri, Func<Exception, bool>)

Adds a new HttpExceptionDescriptor to the enclosed IList<T> of the decorator from the parameters provided.

See Also