Skip to content

Throw for bad requests intended for minimal route handlers in development #36004

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

Merged
merged 14 commits into from
Sep 2, 2021

Conversation

halter73
Copy link
Member

@halter73 halter73 commented Sep 1, 2021

Now instead of having to enable debug logging in development to see why a request is failing with a 400 response, you can easily see why the request is being rejected using the developer exception page or error logs.

This updates the DeveloperExceptionPageMiddleware to preserve the status code requested by the BadHttpRequestException instead of always responding with a 500. This way, the client can still get a 400 response in development but also get more error details.

This also updates the log messages (and the matching Exception messages) to use TypeNameHelper to produce friendlier parameter type names. And this includes the changes from #35580 which I'll close in favor of this.

image

Fixes #35858
Fixes #35857
Fixes #35954

@davidfowl
Copy link
Member

2 things:

  • We should do an API review cc @pranavkm
  • We shouldn't log debug and throw. I think it should be one or the other.

@Tratcher
Copy link
Member

Tratcher commented Sep 1, 2021

  • We shouldn't log debug and throw. I think it should be one or the other.

Agreed, the dev exception page or the server will log at the error level when it catches.

@halter73
Copy link
Member Author

halter73 commented Sep 1, 2021

/backport to release/6.0

@github-actions
Copy link
Contributor

github-actions bot commented Sep 1, 2021

Started backporting to release/6.0: https://github.com/dotnet/aspnetcore/actions/runs/1192214180

@github-actions
Copy link
Contributor

github-actions bot commented Sep 1, 2021

@halter73 backporting to release/6.0 failed, the patch most likely resulted in conflicts:

$ git am --3way --ignore-whitespace --keep-non-patch changes.patch

Applying: Improve RequiredParameterNotProvided log
Applying: Add and flow ThrowOnBadRequest
Applying: Use ThrowOnBadRequest in RequestDelegateFactory
Applying: Add more unit tests
Using index info to reconstruct a base tree...
M	src/Http/Http.Extensions/test/RequestDelegateFactoryTests.cs
M	src/Http/Routing/test/UnitTests/Builder/DelegateEndpointRouteBuilderExtensionsTest.cs
Falling back to patching base and 3-way merge...
Auto-merging src/Http/Routing/test/UnitTests/Builder/DelegateEndpointRouteBuilderExtensionsTest.cs
CONFLICT (content): Merge conflict in src/Http/Routing/test/UnitTests/Builder/DelegateEndpointRouteBuilderExtensionsTest.cs
Auto-merging src/Http/Http.Extensions/test/RequestDelegateFactoryTests.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0004 Add more unit tests
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

@halter73 halter73 enabled auto-merge (squash) September 2, 2021 01:17
@halter73 halter73 merged commit b6000f5 into main Sep 2, 2021
@halter73 halter73 deleted the halter73/35858 branch September 2, 2021 04:27
@ghost ghost added this to the 7.0-preview1 milestone Sep 2, 2021
@amcasey amcasey added area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlewares and removed area-runtime labels Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlewares
Projects
None yet
5 participants