Description
Is there an existing issue for this?
- I have searched the existing issues
Is your feature request related to a problem? Please describe the problem.
The DeveloperExceptionPageMiddleware
catches errors and displays a friendly error page. It can optionally invoke IProblemDetailsService
for its response. When IProblemDetailsService
is called, IExceptionHandlerFeature
is set on the HttpContext
. That change happened earlier this year: #47060
I think we should consider changing the developer exception page middleware again to always set IExceptionHandlerFeature
if the middleware doesn't rethrow the error. The reason to do this is there is no way for earlier middleware or HttpResponse.OnComplete
callbacks to discover what exception was thrown once caught by developer exception middleware.
I noticed this problem when writing some middleware that cares about the exception and is injected by an IStartupFilter
:
- Folder
- StartupFilter - note that it adds the middleware to the start of the pipeline (start and end are the only options, and the end is rarely really a good choice because it will be after terminal endpoint execution). Adding middleware to the start is before UseDeveloperExceptionPage is automatically added by WebApplicationBuilder.
- Middleware - The middleware wants to ensure the unhandled exception is always available in
HttpResponse.OnComplete
callback. Unfortunately, if the developer exception page is present, the exception is always caught and thrown away.
Describe the solution you'd like
Always set IExceptionHandlerFeature
in developer exception middleware so middleware earlier in the pipeline and HttpResponse.OnComplete
can access information about the exception.
Additional context
No response