-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
Reconsider Validation HTTP Status Code #6145
Comments
This comes up from time to time, different people prefer different things. We're interested in ways to make this super easy for you to configure. |
I'm assuming you're referring to the automatic conversion of validation errors into an The It's easy enough to customize it, but it could always be improved. Writing your own quick extension method would be trivial. services.Configure<ApiBehaviorOptions>(options =>
{
options.InvalidModelStateResponseFactory = context =>
{
// Do whatever you want in here, i.e. return an IActionResult or throw an exception.
};
}); The default implementation looks like this: You could swap Otherwise, if you're doing it manually, you can return whatever status code you want. I even added |
@khellang is more of an expert on this (he wrote the code) and can confirm this but I think in 2.2 the default API behaviour is to use the new
So, as well as swapping |
With the above said, I still think there is a case for changing the default to
|
To be honest, I think the explicit status code here should be removed: As MVC now sets the |
@khellang, would you like to send us a PR for this? |
I'll see if I can squeeze it in. Is there any way this can be assigned to me? |
@khellang, feel free to submit a PR and we'll consider it. |
@khellang, and it isn't really possible to assign issues to non-org members. |
Yes, it is. I've been assigned multiple issues in corefx/coreclr 😊 |
Thanks for contacting us. We're closing this issue as there was no community involvement here for quite a while now. |
FYI; httpbis is working on a new HTTP Semantics RFC, obsoleting the current HTTP/1.1 RFCs. One of the interesting things in there is that they're pulling
From the draft. As @rynowak stated in aspnet/Mvc#6789 (comment):
So at least that won't be an issue anymore (assuming the draft is approved) 😄 |
I really wish that they would come out and say - this is for communicating validation/business-rule errors. HTTP is apparently a layer 7 protocol, but you wouldn't get that impression from reading the spec 😢 Using phrases like "contained instructions" doesn't match my mental model of what web servers/frameworks do, and is very hard to reconcile with the semantics of REST. /rant That said, I look forward to seeing this clarified - I still think the spec is pretty unclear, but it's like a 5/10 in unclearness instead of a 7/10. |
Currently the validation pipeline in ASP.NET Core returns a HTTP Status code of
400
which meansBadRequest
.httpstatuses.com describes a status code of
400
as the following:400 BAD REQUEST
I believe the validation pipeline should return a
422
which isUnprocessable Entity
.422 UNPROCESSABLE ENTITY
It should be assumed that if the ASP.NET Core pipeline has a chance to get through model binding and run validators, it means the syntax of the request was valid (especially around an API call).
This change would keep the HTTP status code in the family of
4xx
error codes.The text was updated successfully, but these errors were encountered: