In my ASP.NET Core 2.0 application, I want to throw a 400 Bad Request when there is a syntax problem in the input (eg malformed json) and a 422 Unprocessable Entity for the other errors (eg Required, StringLength etc).
Is there a way to know (maybe looking into ModelState) if it a syntax (400) problem or a validation one (422)?
This is the controller action I am using...
[HttpPost]
public async Task<IActionResult> CreateArticle([FromBody] CreateArticleInput input)
{
if(!ModelState.IsValid)
{
// Return 400 or 422
}
}