What is the response on a REST call where a field is not valid?
        Posted  
        
            by 
                MediaSlayer
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by MediaSlayer
        
        
        
        Published on 2012-09-05T21:36:49Z
        Indexed on 
            2012/09/05
            21:37 UTC
        
        
        Read the original article
        Hit count: 285
        
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?
© Stack Overflow or respective owner