Search results
Results From The WOW.Com Content Network
I agree with your stand that you should get a status code that shows something went wrong. This is after all what status codes are for. Also you get the benefit of libraries that throw exceptions/etc. on non-200 status code so you do not have to check explicitly (Or you can write your own wrapper that does this).
Instead, you should throw new NotFoundException(); to indicate to the framework that the entry doesn't exist, so that it would generate a HTTP 404. If I should change it to a 404, obvious question: I should change the method signature right? No, you don't. That's the nice thing about throw new NotFoundException();. It will work no matter what ...
This code usually makes web browsers to redirect to a specific location (URI) informed in the response headers. This might not be your case, but it's important to know about this. Ultimately, HTTP status codes are addressed to HTTP clients. Not to our applications. Not to persons.
Unlike 404, 400 means "ok, the resource does exist, the request has been handled but could not be processed because something is missing, wrong-formated or the content doesn't make sense. Fix the issues and try again". Remember that HTTP status codes are always addressed to HTTP clients, not to the business, not the application.
Always decide which range your response code should be in first. Doing so quickly eliminates a lot of response codes as options, and (maybe more importantly) it makes following the semantics of the codes much simpler. See the beginning sections of the HTTP code documentation for the explanations of what each category of codes represents.
1. 404 is a client asking (or guessing) for something nobody knows if it exists. The server looks for it and it does not fail at searching. it just doesn't find it. 500 is the server failing at searching/serving the file due to a crash that was not meant to happens. – Laiv.
I like 403, or 404, leaning toward 404. 403 might encourage them to try different tactics. 404 implies the page just isn't there at all and it's a bad URL. I've written a lot of spiders for past jobs, and seldom saw 403, but ran into lots of 404s. Either way my code would remove the URL from the queue, but that's because I was trying to play fair.
404 Not Found; The server has not found anything matching the Request-URI. No indication is given of whether the condition is temporary or permanent. The 410 (Gone) status code SHOULD be used if the server knows, through some internally configurable mechanism, that an old resource is permanently unavailable and has no forwarding address.
HTTP status codes are extensible. HTTP applications are not required to understand the meaning of all registered status codes, though such understanding is obviously desirable. However, applications MUST understand the class of any status code, as indicated by the first digit, and treat any unrecognized response as being equivalent to the x00 ...
The 422 (Unprocessable Entity) status code means the server understands the content type of the request entity (hence a 415(Unsupported Media Type) status code is inappropriate), and the syntax of the request entity is correct (thus a 400 (Bad Request) status code is inappropriate) but was unable to process the contained instructions.