Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Accept HTTP header affect returned content when dealing with exceptions?

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?

like image 411
slbruce Avatar asked Dec 04 '25 07:12

slbruce


1 Answers

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.

like image 113
Nathan Avatar answered Dec 05 '25 22:12

Nathan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!