-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Create a pattern to have the framework handle validation errors automatically #6789
Comments
Could I propose From RFC4918 Section 11.2:
It's kinda sad that syntax and semantics are conflated in the MVC validation system today 😢 |
I guess my comment is related to #4862 |
You can propose whatever you want 😆 To me it's not the most important thing - because even if we can choose a right answer there will still be lots of developers who want to do it differently. I still welcome the discussion, but I don't expect us to get an overwhelming consensus.
In my readings of a few other blogs and forum posts this morning on the topic of 400 vs 422 I came across a lot of cases where the author totally misunderstands what 'syntax' is. I'm currently busy being sad about that 😢 What would you have us do to improve this? The big barrier that I see is that we don't really have an input validation system at all. We only have a model validation system. Regarding HTTP 422: Some people are bothered by the fact that 422 is defined by the WebDAV RFC and it's not mentioned at all in RFC7231 which came 7 years later. I don't think this is a big deal, 422 is in common use for this purposes. The part that I have trouble with is that 422 is that it is specific about the As you pointed out, we don't have a clear separation between syntax and semantics. We're also generally operating pretty far away from the actual Consider also that the language for 400 was revised by RFC7231 Old
New
The changes specifically drop the language that states that 400 is intended for cases where the request syntax is incorrect. It's now considered an example of when a 400 is appropriate. I've also heard arguments in the past for 409 for generic validation errors, which I do not find persuasive. 409 could be appropriate for some business rule kinds of validations but it's not a good 'general' choice. |
Why do you even involve the model state and hit the action method on syntactical errors? I'm not sure what you expect the developer to do in this case?
I would just return 400 right away, but I'm probably missing something 😅 |
At the very least, it would be nice if the status code was configurable 😄 |
Yeah this is part of the spirit of this work item.
Absolutely |
This would be a filter that responds with a 400 without calling your action code.
The text was updated successfully, but these errors were encountered: