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:
@@ -26,11 +26,11 @@ public record HttpExceptionHandler(Type ExceptionType, Func<HttpContext, Excepti
|
||||
#region Default handlers
|
||||
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) =>
|
||||
{
|
||||
context.Response.ContentType = "application/json";
|
||||
|
||||
Reference in New Issue
Block a user