Reputation: 910
I'm working on a small web application, and I'm trying to decide if I should make the effort to emit semantically appropriate HTTP status codes from within the application.
I mean, it makes sense for the web server itself to emit proper response codes. 500 Internal Server Error
for a misconfigured Apache or 404 Not Found
for a missing index.php
or whatever all make sense, since there's nothing else the server can really do.
It also makes sense to manipulate the browser with 303 See Other
or other HTTP mechanisms which actually produce behavior.
But if all that happened is a missing GET
parameter, for example, is there any reason to go out of my way to return 400 Bad Request
? Or how about 404 Not Found
, if my application is handling all the routing by itself? From what I can tell there isn't any behavior associated with either of those error codes.
Upvotes: 1
Views: 144
Reputation: 39
I think its very important for a web service to respond with appropriate codes as sometime the developer using the service might not know whats wrong or why the app stopped working unless he views the status code.
Upvotes: 0
Reputation: 2481
My general opinion: provide codes if the code provides actionable data for the user.
If all you're doing is presenting content, then in most cases I think it's less important. If YouTube fails to load a video, I mostly care about the fact that I can't watch my video. That it failed with a 418
status might be intellectually interesting, but it doesn't really provide me with any helpful information (Even assuming a non-silly failure code).
On the other hand, if you're allowing some kind of user interaction with a server, then the codes become much more important. I might actually care about why my request failed, because I'm now in a position to do something about it.
However, there are some codes that are actionable. 410 Gone
for example: If my request failed for that reason, but I just got back a generic "Stuff Broke" message, I'd probably repeat the request a bunch of times, get nowhere, and give up in frustration. Knowing that the thing I'm looking for doesn't exist is a pretty useful thing for me to know.
Upvotes: 2