HttpStatusCodeExceptionDecoratorExtensions Class
Definition
- Namespace
- Cuemon.AspNetCore.Http
- Assemblies
- Cuemon.AspNetCore.dll
Extension methods for the HttpStatusCodeException class hidden behind the IDecorator<T> interface.
public static class HttpStatusCodeExceptionDecoratorExtensions
- Inheritance
-
objectHttpStatusCodeExceptionDecoratorExtensions
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
| Name | Description |
|---|---|
| AddResponseHeaders<T>(IDecorator<T>, IHeaderDictionary) | Adds all non-existing |
| AddResponseHeaders<T>(IDecorator<T>, HttpResponseHeaders) | Adds all non-existing |
See Also
IDecorator<T>
Decorator<T>