architecture - Handling Error Messages -
Recently, I wanted to separate communication between client and server in a rich web application, which is made up of most widgets. Was there. Responses to the client are in a JSON format when the error message was time to make decisions about arranging two cases.
-
Send feedback error parts such as
{"success": "false", "errors": ["field 1": "message 1 "," Field 2 ":" Message2 "]}
-
Send errors as headers and just return false to react ('X-application-error ',' ["Field 1": "message1", "field2": "message2"] ')
/ P>
The second option is clearly visible; The user only checks the errors in the header, when they want, the errors seem to be in this way to become part of the protocol instead of being part of the reaction.
Is this a good practice? One way is better than the other.
I will send an error message as part of the response.
Adding custom headers is what you want to report things at the HTTP protocol level; HTTP has established methods of reporting errors (via HTTP status code) I will leave the thing which will be shown to the customer in the body of the response (or used by Javascript).
Comments
Post a Comment