-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
ProblemDetails is not returned for 404NotFound and 500Exception #4953
Comments
try to use routetemplate [HttpGet("/notfound/{text}")] |
Y NO USE MY MIDDLEWARE? 🤔 😢 |
@khellang but I am :) and it's great! Just seeing if the feature could be further expanded/completed or ... not (which means we all stick with yours). It just feels incomplete, right now. Sure, this 'might be as designed' but I thought .. when comparing your middleware to the one in MVC .. there's a heap of gaps. I also understand that this can be compared to the MS IoC/DI vs structuremap, etc. (3rd parties). I feel that the MS DI is really usable for seriously most "common" scenarios - very workable. But comparing the the MS ProblemDetails stuff, I don't think it's complete for "common" scenario's. |
Thanks for contacting us, @PureKrome. |
cc @rynowak \ @JamesNK for thoughts about 404 from routing. IMO, our philosophy has been to use It's fairly trivial to configure the filter to respond to additional status codes (https://github.com/aspnet/AspNetCore/blob/release/2.2/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApiBehaviorOptions.cs#L194-L203). Even if we configured it to handle 5xx status codes, we wouldn't add an exception filter \ do exception handling by default (too opinionated, breaks existing logging and exception handling etc). I'm not sure if it would be of much use in this configuration. |
@pranavkm thanks heaps for jumping into this issue 👍
Ok - so based upon this answer, what you're suggesting is that you think it's totally fine/acceptable to have mixed results for a standard Web/REST Api website (** I hate those names to describe an API website but it's a common way to describe these apps). Mixed == sometimes we get problem details. Other times, we don't get PD's and (by default I think) just a status code. vs An API website that returns PD's for any non 200 response. |
@glennc thoughts on this? |
I agree with @PureKrome, the main reason, because I have enabled ProblemDetails, was one fine data structure to resolve problems with error handling. That's really important. Please, consider how to include other status codes into ProblemDetails as default. |
/cc @davidfowl who spent some time looking at this. a) With 500s, you could use the error handler to point to an MVC action and have that return b) 400s have the same solution using either While the templates aren't exactly wired up to do this, it does seem like there are enough building blocks to meet your goals. What do you think? |
Yep - there are enough building blocks to do this. As a case in point, I did this nearly a year ago and have been using this in various .NET apps. I guess my main request was to try and bake this more into the common template stuff. Part of the issue here was that having a webapi only handle some errors are problem-details feels like an incomplete solution. Think about it -> why would a webapi only return some errors as PD's while other scenario's as .. not-PD's? So the discussion was more about having a consistent solution across a webapi template. |
I tested this with the latest 3.0.100 SDK and 404 and 500 now correctly return However, 406 Not Acceptable responses which are returned when you enable |
@RehanSaeed wait what? So 5xx errors now return If yes, wish there was some info dropped into this thread to give us some exciting news, etc... |
AFAIK, this should only be for 500 @RehanSaeed would you mind filing a separate issue for the 406 scenario? We'll need to do something nicer here: https://github.com/aspnet/AspNetCore/blob/4c67855ccfb77e4e06087aa7d61f1d4894716af4/src/Mvc/Mvc.Core/src/Infrastructure/ObjectResultExecutor.cs#L150-L154 |
Cheers @pranavkm ! Okay - so nothing new has changed and the initial question still remains a valid one. We understand that we can do some custom code to handle this stuff ... but the root question remains valid, IMO. So far, what I'm reading is this (unfortunately):
As such, can you please explain the reasoning for this hybrid behavior? To keep things simple, can you use the
|
This is because the behavior is MVC-specific. If a path doesn't match any routes, MVC won't even touch the request and fall through. Without middleware to handle this on the way back, there's no way to be consistent here... |
Yep correct! that's the technical reason why this is currently occurring. I'm hoping the product team can answer why they prefer this hybrid result and explain the reasoning for it. I'm not hating, just trying to learn and understand the decision, here. |
@PureKrome it's a non-trivial amount of work to move |
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process. |
Thanks @captainsafia for the update! Really appreciate it 😄 🍰 Despite not being the best answer, there's still hope this can get some more love, next release. It's nice to see that tough decisions can be made and then explained to us - so cheers. @khellang your code lives for another day! |
Thanks for contacting us. We're moving this issue to the |
Good to see this being looked at again for .NET 7. Please also remember to consider this related issue: |
@brunolins16 any chance for a quick summary of what ended up getting merged/added to the codebase? |
@PureKrome here is the final API #42212 (comment). Basically, it is the introduction of the That means, for your very initial example: you could get a full ProblemDetails generation, adding this your code: builder.Service.AddProblemDetails() and adding the following middleware: app.UseExceptionHandler();
app.UseStatusCodePages(); |
Also, it is important to mention, for now, it is not a total replacement to @khellang's middleware, if your app has a lot customizations, eg. Map Exceptions, etc., however, I am planning to create issues, almost sure targeting .NET 8, asking for new features for both |
Describe the bug
Given a new ASPNET Core 2.2 "API" Website,
ProblemDetails
are not returned when:ActionMethod
.I understand that currently
ProblemDetails
are provided when aController
is decorated withApiController
. So the first scenario (route doesn't exist/match) can't currently be handled. The second scenario (exeception thrown) is inside anController/ActionMethod
that has been decorated.ProblemDetails
should apply globally, not just on a half-specific set of scenario's. This breaks application-consistency.Currently, the only workaround is to use @khellang 's
ProblemDetails
nuget library (part of his 'Middleware' repo).Would be very helpful to either consider:
a) implementing the full functionality
b) just removing it because the current implementation feels inconsistent / half-complete. (NOTE: please don't remove it! lets complete it!!)
To Reproduce
Startup.cs
. Comment out\\ app.UseDeveloperExceptionPage();
Controllers\ValuesController
to (more or less) the following:I've just added some specific routes to test problem details. (look below 😎 )
Expected behavior
ProblemDetails
to be returned.IsDevelopment
mode.Startup.cs
.Additional context
Also using
Visual Studio 15.9.4
polite cc @glennc
Thank you kindly for your awesome work and here's Dwayne/TheRock singing sweet nothings to help persuade the decision process, here. Like, who would say 'no' to TheRock??
The text was updated successfully, but these errors were encountered: