Reputation: 103
I have a REST resource that returns a jpeg image for example. The user sets as his accept header "image/jpeg." However a problem occurs on the server such as the image not existing. We want to return that exception to the user. Normally this exception can be returned as xml, json or html.
Is it acceptable behaviour to default to a html exception or should the return exception be as type jpeg and therefore gibberish?
Upvotes: 3
Views: 242
Reputation: 335
As Celeda says in the comment above, it is perfectly fine to return a different content type than is declared in "Accept". The authors encourage the return of error messaged in the body when error conditions exist.
The Accept header is simply a way for the server to be guaranteed that it has generated a response that the client considers "acceptable". Errors are, by definition, not acceptable (at least they aren't to my clients :) so the format is kind of irrelevant. Certainly, jpeg gibberish wouldn't be acceptable.
Upvotes: 2