What is the response on a REST call where a field is not valid?
- by MediaSlayer
There are many questions on StackOverflow about this, but no definitive answer.
I have a REST resource where an entity's field, ProductId, is sent. If the ProductId passed is invalid, what kind of response would you do?
I want to send the right response code plus information to the requester on what they can do to fix it.
Initial thoughts were 422 with the body containing the list of errors in JSON/XML format. Maybe like this (JSON):
[
{ FieldName : "ProductId", ErrorCode : "M123", Description : "Product Not Found" },
{ FieldName : "Quantity", ErrorCode : "Q001", Description : "Quantity cannot be more than 100" }
]
Thoughts?