Does HTTP require that the server return one of the accept header media types on an error? For instance we perform a POST with the accept header application/vnd.foo.bar-v1+json
and error occurs and the result is a 422. Do we need to return the application/vnd.foo.bar-v1+json or can we return a different media type since an error occured? Could I return a application/vnd.foo.errors-v1+json?
Looking a W3 http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html I did not see an outright explanation.
From https://www.rfc-editor.org/rfc/rfc7231#section-6.5:
What this means is that the body of the response should contain the error, and the
Content-Type
identifies its type. For example, by default Tomcat returns an HTML page, so theContent-Type
is set appropriately (totext/html
, I believe).If your error has the media type
application/vnd.foo.bar-v1+json
then you should set it as theContent-Type
.