Table of Contents

HttpExceptionDescriptorResponseHandler Class

Definition

Provides a way to support content negotiation for HttpExceptionDescriptor.

public class HttpExceptionDescriptorResponseHandler
Inheritance
object
HttpExceptionDescriptorResponseHandler

Examples

The following example demonstrates how to use HttpExceptionDescriptorResponseHandler to write structured error responses.

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

        namespace Cuemon.AspNetCore.Diagnostics;

        public static class HttpExceptionDescriptorResponseHandlerExample
        {
            public static void Demonstrate()
            {
                var handler = HttpExceptionDescriptorResponseHandler.CreateDefaultFallbackHandler(FaultSensitivityDetails.None);
        var exceptionDescriptor = new HttpExceptionDescriptor(new BadRequestException());

        using var response = handler.ToHttpResponseMessage(exceptionDescriptor);
        Console.WriteLine($"{(int)response.StatusCode} {handler.ContentType.MediaType}");
            }
        }

Constructors

Name Description
HttpExceptionDescriptorResponseHandler(MediaTypeHeaderValue, Func<HttpExceptionDescriptor, HttpResponseMessage>)

Initializes a new instance of the HttpExceptionDescriptorResponseHandler class.

Properties

Name Description
ContentType

Gets the media type that this handler supports.

Methods

Name Description
CreateDefaultFallbackHandler(FaultSensitivityDetails)

Creates a scaled down HttpExceptionDescriptorResponseHandler suitable as fallback handler for when content negotiation fails.

ToHttpResponseMessage(HttpExceptionDescriptor)

Converts this instance into an HttpResponseMessage from the by constructor provided factory.