-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Initial design for exception page filters #8958
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
df9da55
786a8fa
b14d33c
4a68f3d
0328ea0
2cdf95b
8a1a164
ffca724
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ public class DeveloperExceptionPageMiddleware | |
private readonly IFileProvider _fileProvider; | ||
private readonly DiagnosticSource _diagnosticSource; | ||
private readonly ExceptionDetailsProvider _exceptionDetailsProvider; | ||
private readonly Func<HttpContext, Exception, Task> _exceptionHandler; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="DeveloperExceptionPageMiddleware"/> class | ||
|
@@ -40,12 +41,14 @@ public class DeveloperExceptionPageMiddleware | |
/// <param name="loggerFactory"></param> | ||
/// <param name="hostingEnvironment"></param> | ||
/// <param name="diagnosticSource"></param> | ||
/// <param name="filters"></param> | ||
public DeveloperExceptionPageMiddleware( | ||
RequestDelegate next, | ||
IOptions<DeveloperExceptionPageOptions> options, | ||
ILoggerFactory loggerFactory, | ||
IWebHostEnvironment hostingEnvironment, | ||
DiagnosticSource diagnosticSource) | ||
DiagnosticSource diagnosticSource, | ||
IEnumerable<IDeveloperPageExceptionFilter> filters) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. breaking change yo There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I know but it's 3.0 and I'm expecting this to be acceptable. I didn't update the refs tho because who ever remembers that the first time 😄 |
||
{ | ||
if (next == null) | ||
{ | ||
|
@@ -63,6 +66,13 @@ public DeveloperExceptionPageMiddleware( | |
_fileProvider = _options.FileProvider ?? hostingEnvironment.ContentRootFileProvider; | ||
_diagnosticSource = diagnosticSource; | ||
_exceptionDetailsProvider = new ExceptionDetailsProvider(_fileProvider, _options.SourceCodeLineCount); | ||
_exceptionHandler = DisplayException; | ||
|
||
foreach (var filter in filters.Reverse()) | ||
davidfowl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
var nextFilter = _exceptionHandler; | ||
_exceptionHandler = (context, exception) => filter.HandleExceptionAsync(context, exception, nextFilter); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the CoR is so elegant and cool |
||
} | ||
|
||
/// <summary> | ||
|
@@ -91,7 +101,7 @@ public async Task Invoke(HttpContext context) | |
context.Response.Clear(); | ||
context.Response.StatusCode = 500; | ||
|
||
await DisplayException(context, ex); | ||
await _exceptionHandler(context, ex); | ||
|
||
if (_diagnosticSource.IsEnabled("Microsoft.AspNetCore.Diagnostics.UnhandledException")) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Http; | ||
|
||
namespace Microsoft.AspNetCore.Diagnostics | ||
davidfowl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
public interface IDeveloperPageExceptionFilter | ||
davidfowl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
Task HandleExceptionAsync(HttpContext context, Exception exception, Func<HttpContext, Exception, Task> next); | ||
davidfowl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this are some hq docs