Class HttpStatusCodeExceptionDecoratorExtensions
- Namespace
- Cuemon.AspNetCore.Http
- Assembly
- Cuemon.AspNetCore.dll
Extension methods for the HttpStatusCodeException class hidden behind the IDecorator<T> interface.
public static class HttpStatusCodeExceptionDecoratorExtensions
- Inheritance
-
HttpStatusCodeExceptionDecoratorExtensions
Examples
The following example demonstrates how to add response headers to an HttpStatusCodeException using the decorator pattern.
using System.Net.Http;
using System.Net.Http.Headers;
using Cuemon.AspNetCore.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Primitives;
using Cuemon;
namespace Examples;
public class HttpStatusCodeExceptionHeadersExample
{
public void AddHeadersToException()
{
var exception = new NotFoundException("Resource not found.");
var headers = new HeaderDictionary
{
{ "X-Correlation-Id", new StringValues("abc-123") },
{ "X-Request-Id", new StringValues("req-456") }
};
Decorator.Enclose(exception).AddResponseHeaders(headers);
using var message = new HttpResponseMessage();
message.Headers.Add("X-Server-Id", "server-01");
Decorator.Enclose(exception).AddResponseHeaders(message.Headers);
}
}
Methods
AddResponseHeaders<T>(IDecorator<T>, IHeaderDictionary)
Adds all non-existing headers to the enclosed HttpStatusCodeException of the decorator.
public static IDecorator<T> AddResponseHeaders<T>(this IDecorator<T> decorator, IHeaderDictionary headers) where T : HttpStatusCodeException
Parameters
decoratorIDecorator<T>The IDecorator<T> to extend.
headersIHeaderDictionaryThe IHeaderDictionary to populate into the enclosed HttpStatusCodeException.
Returns
- IDecorator<T>
Type Parameters
T
Exceptions
- ArgumentNullException
decoratorcannot be null -or-headerscannot be null.
AddResponseHeaders<T>(IDecorator<T>, HttpResponseHeaders)
Adds all non-existing headers to the enclosed HttpStatusCodeException of the decorator.
public static IDecorator<T> AddResponseHeaders<T>(this IDecorator<T> decorator, HttpResponseHeaders headers) where T : HttpStatusCodeException
Parameters
decoratorIDecorator<T>The IDecorator<T> to extend.
headersHttpResponseHeadersThe HttpResponseHeaders to populate into the enclosed HttpStatusCodeException.
Returns
- IDecorator<T>
Type Parameters
T
Exceptions
- ArgumentNullException
decoratorcannot be null -or-headerscannot be null.
See Also
IDecorator<T>
Decorator<T>