/// <summary> /// Adds a middleware to the pipeline that will catch exceptions, log them, reset the request path, and re-execute the request. /// The request will not be re-executed if the response has already started. /// </summary> /// <param name="app"></param> /// <param name="errorHandlingPath"></param> /// <returns></returns> public static IApplicationBuilder UseErrorHandler(this IApplicationBuilder app, string errorHandlingPath) { var options = new ErrorHandlerOptions() { ErrorHandlingPath = new PathString(errorHandlingPath) }; return app.UseMiddleware<ErrorHandlerMiddleware>(options); }
public ErrorHandlerMiddleware(RequestDelegate next, ILoggerFactory loggerFactory, ErrorHandlerOptions options) { _next = next; _options = options; _logger = loggerFactory.CreateLogger<ErrorHandlerMiddleware>(); if (_options.ErrorHandler == null) { _options.ErrorHandler = _next; } }
public ErrorHandlerMiddleware(RequestDelegate next, ILoggerFactory loggerFactory, ErrorHandlerOptions options) { _next = next; _options = options; _logger = loggerFactory.Create <ErrorHandlerMiddleware>(); if (_options.ErrorHandler == null) { _options.ErrorHandler = _next; } }
/// <summary> /// Adds a middleware to the pipeline that will catch exceptions, log them, and re-execute the request in an alternate pipeline. /// The request will not be re-executed if the response has already started. /// </summary> /// <param name="app"></param> /// <param name="configure"></param> /// <returns></returns> public static IApplicationBuilder UseErrorHandler(this IApplicationBuilder app, Action<IApplicationBuilder> configure) { var subAppBuilder = app.New(); configure(subAppBuilder); var errorPipeline = subAppBuilder.Build(); var options = new ErrorHandlerOptions() { ErrorHandler = errorPipeline }; return app.UseMiddleware<ErrorHandlerMiddleware>(options); }
public ErrorHandlerMiddleware(RequestDelegate next, ILoggerFactory loggerFactory, ErrorHandlerOptions options) { _next = next; _options = options; _logger = loggerFactory.CreateLogger <ErrorHandlerMiddleware>(); if (_options.ErrorHandler == null) { _options.ErrorHandler = _next; } _clearCacheHeadersDelegate = ClearCacheHeaders; }