dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.4k stars 10k forks source link

Allow the usage of the ExceptionHandlerMiddleware without any configurations #21902

Closed ivanhoe-k closed 3 years ago

ivanhoe-k commented 4 years ago

Is your feature request related to a problem? Please describe.

Relates to #21893

Describe the solution you'd like

The ExceptionHandlerMiddleware can be used by calling different extension methods that are defined in the ExceptionHandlerExtensions. One of those methods is parameterless that in my opinion should mean the ability to use it without any configurations. But it is not possible right now due to the exception I mentioned here #21893. If I understand correctly before using the parameterless version of the UseExceptionHander() extension method we should also provide options in ConfigureServices. I would say it's a little bit tricky and it would be great to allow not to specify any configurations in order to have the opportunity to use the default logic of the ExceptionHandlerMiddleware (logging, adding exception handler features to the response, etc.).

I come up with this small suggestion because I do really need this feature in my project. The middleware handles unhandled exceptions out of the box and does everything to handle it properly (no CORS errors on the client side when the unhandled exception occurs #2378). I know that we can create our own middleware or define some stubs, like this

app.UseExceptionHandler(
                errorApp => errorApp.Run(_ => Task.CompletedTask));

It doesn't look like the right way and in case of creating custom middlewares it looks to me like code duplication, the same as creating own exception when there is already suitable one out of the box.

Tratcher commented 4 years ago

How does that empty errorApp address the CORS issue? Or is that an additional problem you're trying to address?

With that empty erroApp you'd get almost the same behavior if you removed the middleware and used the server's default exception handling logic.

ghost commented 3 years ago

Thank you for contacting us. Due to a lack of activity on this discussion issue we're closing it in an effort to keep our backlog clean. If you believe there is a concern related to the ASP.NET Core framework, which hasn't been addressed yet, please file a new issue.

This issue will be locked after 30 more days of inactivity. If you still wish to discuss this subject after then, please create a new issue!