We are developing a standard REST service using HTTP status codes as the response code if something went wrong. (for example, an incorrect user input will return a "400 Bad Request" to the client)
However, we felt that a more detailed error message would be useful to the client. (for example, an invalid input error is due to the fact that X is an unrecognized parameter name)
We would like to be as precise as possible for the HTTP specifications, therefore, having studied the specification in RFC2616 , we are thinking about putting a detailed error in the HTTP headers, in particular in the HTTP header warning field. He told the RFC that:
The general Warning header field is used to carry additional information about the status or conversion of a message that may not appear in the message . This information is usually used to warn of the possible absence of semantic transparency from caching operations or transformations applied to the message body.
There seems to be no restriction on the use of this header for other warnings (such as a REST error message), even those not related to cache warnings in accordance with the original intent of this header. We like the semantics, and we planned to use the warning code 299, which seems to fit the bill pretty well:
299 Other constant warning. The warning text MAY include arbitrary information that must be presented to the user or registered . The system receiving this warning SHOULD NOT take any automatic action.
So, given the incorrect input of the error presented at the top of this question, we are thinking about putting our REST error message, as in the following example:
HTTP/1.1 400 Bad Request Warning: 299 ServiceName "Invalid input error: X is unrecognized parameter name."
Is this a good idea / practice? We also found that some services describe this message in detail in the X-Warning header, but this seems not standard. We wonder what will think about it. Is there also a more efficient / standardized practice for sending detailed error messages in REST responses?
Ibrahim Arief Jul 13 2018-11-11T00: 00Z
source share