-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Add extensible handlers to DeveloperExceptionPage #8536
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
Comments
As a strawman design for the first part of this issue, we could introduce a simple interface like this: public interface IDeveloperPageExceptionFilter
{
Task HandleExceptionAsync(HttpContext context, Exception exception, Func<HttpContext, Exception, Task> next);
} This follows the filter pattern we have elsewhere in the product (middleware, startup filters etc)
We could provide an |
This pattern seems OK, how do we decide on the order? Are these in DI or options? What's the lifetime? Those are some of the rough edges in MVC's filters. If it's based on options then the answers are pretty straightforward IMO. +1 for the idea of chain of responsibility here. Is the idea that we register the current behaviour as the last filter? I'm not sure the idea of transforming the exception is valuable. I think it's fine if the contract allows it, but I don't see why its necessary. I don't think we need a context here. If we get that far, we might want to consider using features or enhancing existing contracts on http context. note: since nothing clears the endpoint on throw - you could use endpoint metadata in one of these filters. |
DI order, like IStartupFilters. I don't think the order will matter that much in practice as I'm hoping the majority use case is to filter on exception type if you're not wholesale changing exception formatting (then you just need to be the first).
DI.
Singleton
Turning an Aggregate into something else or a TargetInvocationException into something. It might be contrived but we'll see what people do.
👍 That's pretty useful. |
I think there's another important dimension here - what is the client? We've wanted for a while to have a JSON version for APIs. If the framework registers handlers for you then it won't be straightforward to resolve ordering problems.
If that's the case though, then I wouldn't do it that way as a user. It's a little too clever. If there are places the framework always throws a TIE or an AggyBoy we should treat those as bugs should being unwrapping for you. |
Imagine registering a handler that does problemdetails for an API based on |
That's a good question. If you look at the original issue, we also want to change the output to the plain text exception if text/html isn't in the accept header (or if there's no accept header). That's the lowest common denominator and wouldn't be expressed as a filter (it'll just be built in). So that was the intent. If a filter ends up being greedy it'll never run but I don't know that we want to do any more complicated matching (content type/metadata/exception type). I think in a typical application with MVC and EF, we'll have 2 of these filters:
The EF one will show up only if the exception is of a specific type so it won't be greedy. Can you think of other things that might cause issues in practice?
Maybe, it means you lose the ability to do your own formatting of those types of exceptions. I wouldn't want to hide that type of information. I just threw that out as a possible example of a thing that would change the exception type. I don't know if anyone would ever need to do it though. |
FYI here are previous bugs tracking related (similar/same) stuff:
If the 'very related' bugs are entirely covered by this, should close those. |
I'm referring to cases where the TIE or AggyBoy doesn't have any information. If you use reflection to invoke a method, there's no real downside to unwrapping the TIE you get back. Likewise for a I realise this is just banter at this point 😆 |
Moving this to preview5, here's what I think we should do:
|
So in the con-neg you want plaintext to be the fallback? Or should the real fallback still be text/html if no Accept-Type is sent? |
If you were doing real content negotiation you'd be honoring the client's Accept ordering preference. That doesn't match up with this pipeline model as well. text/plain is the safest fallback, and the easiest to understand in the common dev/debug scenario. I always hate having to dig through HTML in the debugger, test logs, etc.. |
Con-neg doesn't require honoring anything! 😄 And it says nothing about the ultimate fallback in case no desired content types are supported. I agree that plaintext is simplest to see, but I wanted to understand if there's any consideration to "compatibility" or "doing what most people would expect." |
With #9342 merged, is this done? We now have a plain-text exception page. |
Yes I'll file another IIS for the other work items (MVC and EF) |
As far as I can see, this item should not be marked as done, as it only addresses the second point in the OP. The first is still very much a missing feature. |
Not sure what you mean. |
Add extensibility point to sub-systems to add handlers via DI that get inspected when an exception occurs. The handler can choose to render a response (e.g. the current EF diagnostic middleware page would change to this) or pass-through (do nothing). The middleware would fallback to rendering an HTML error page if no handler matched and the client sent an Accept header that included text/html, otherwise it would just return the error as plain text. For API responses, MVC would register a handler that formats a
ProblemDetails
with the relevant information according to the configured formatters.There's 2 work items here:
The text was updated successfully, but these errors were encountered: