Table of Contents

HttpFaultResolverExtensions Class

Definition

Extension methods for the HttpFaultResolver class.

public static class HttpFaultResolverExtensions
Inheritance
HttpFaultResolverExtensions

Examples

The following example builds a resolver list the same way MVC fault handling does internally: map known exception types to HTTP-friendly descriptors, then ask a resolver to translate the thrown exception.

// Program.cs
using System;
using System.Collections.Generic;
using Cuemon.AspNetCore.Diagnostics;
using Cuemon.AspNetCore.Http;
using Cuemon.Extensions.AspNetCore.Mvc.Filters.Diagnostics;

var resolvers = new List<HttpFaultResolver>()
    .AddHttpFaultResolver<BadRequestException>(
        message: "The request payload could not be processed.",
        helpLink: new Uri("https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/400"))
    .AddHttpFaultResolver<TooManyRequestsException>(
        exception => new HttpExceptionDescriptor(exception),
        exception => exception is TooManyRequestsException);

var resolved = resolvers[1].TryResolveFault(new TooManyRequestsException(), out var descriptor);

Console.WriteLine($"{resolved}: {descriptor.StatusCode} {descriptor.Code}");

Methods

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

Adds the specified function delegate exceptionDescriptorResolver and function delegate exceptionValidator to the collection of descriptors.

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

Adds a new HttpExceptionDescriptor to the collection of descriptors from the parameters provided.

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

Adds a new HttpExceptionDescriptor to the collection of descriptors from the parameters provided.