Recently I had to standarize communication between the client and the server in a rich web application composed mostly of widgets. Responses to the client are in a json format. When it was time to decide about handling error messages two ideas popped up.
Send the errors message part of the response such as
{"success":"false","errors":["field1":"message1","field2":"message2"]}
Send the errors as a header and simply return false to client
response.addHeader('X-Application-Error','["field1":"message1","field2":"message2"]')
The second option seems to be neat; the user only checks for errors in the headers when they want to, the errors seems this way to be part of the protocol rather than be part of the response.
Is this a good practice ? Is one way better than the other.