-
Notifications
You must be signed in to change notification settings - Fork 45
Open
Description
JSON API specifies a format for so-called "error objects". While I could create such error documents myself, I would be interested to see what would be needed to support creating such documents based on ModelState validation.
An example from the JSON API site:
HTTP/1.1 422 Unprocessable Entity
Content-Type: application/vnd.api+json
{
"jsonapi": { "version": "1.0" },
"errors": [
{
"code": "123",
"source": { "pointer": "/data/attributes/firstName" },
"title": "Value is too short",
"detail": "First name must contain at least three characters."
},
{
"code": "225",
"source": { "pointer": "/data/attributes/password" },
"title": "Passwords must contain a letter, number, and punctuation character.",
"detail": "The password provided is missing a punctuation character."
},
{
"code": "226",
"source": { "pointer": "/data/attributes/password" },
"title": "Password and password confirmation do not match."
}
]
}For reference, the default output of ModelState looks like this:
if (!ModelState.IsValid)
throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));{
"Message": "The request is invalid.",
"ModelState": {
"category.Name": [
"The field Name must be a string or array type with a minimum length of '20'."
]
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels