Refactor HttpExceptionHandler to use properties
Changed DefaultBadRequest, DefaultNotFound, and Default from readonly fields to properties for lazy evaluation, enhancing performance and flexibility while maintaining the same functionality.
This commit is contained in:
parent
2c393701e4
commit
fd8e976e1e
@ -26,11 +26,11 @@ public record HttpExceptionHandler(Type ExceptionType, Func<HttpContext, Excepti
|
|||||||
#region Default handlers
|
#region Default handlers
|
||||||
public static readonly Func<Exception, string> DefaultMessageFactory = ex => ex.Message;
|
public static readonly Func<Exception, string> DefaultMessageFactory = ex => ex.Message;
|
||||||
|
|
||||||
public static readonly HttpExceptionHandler DefaultBadRequest = Create<BadRequestException>(HttpStatusCode.BadRequest, DefaultMessageFactory);
|
public static HttpExceptionHandler DefaultBadRequest => Create<BadRequestException>(HttpStatusCode.BadRequest, DefaultMessageFactory);
|
||||||
|
|
||||||
public static readonly HttpExceptionHandler DefaultNotFound = Create<NotFoundException>(HttpStatusCode.NotFound, DefaultMessageFactory);
|
public static HttpExceptionHandler DefaultNotFound => Create<NotFoundException>(HttpStatusCode.NotFound, DefaultMessageFactory);
|
||||||
|
|
||||||
public static readonly HttpExceptionHandler Default = Create<Exception>(
|
public static HttpExceptionHandler Default => Create<Exception>(
|
||||||
async (context, ex, logger) =>
|
async (context, ex, logger) =>
|
||||||
{
|
{
|
||||||
context.Response.ContentType = "application/json";
|
context.Response.ContentType = "application/json";
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user