开发者

Should I Return "500" or "404" if a Requested Image is not Found?

I work with code written by other people, occasionally I am left somewhat confused and at these times Stack Overflow saves me. Please, save me again.

Our site allows people to upload images and later embed them within text in our site like so:

<img src="http://site.com/im开发者_如何学Pythonage_script.php?p=some_image_identifier"/>

My question is:

If the identifier, "p", does not lead us to an image should the server return "500" or "404"?

I would have thought it should be "404", but that's not what is happening right now.


500 is an error in fulfilling the request. So if the request processed fine and the file is not found, you should return a 404.


404 would be (imho) more appropriate. 500 indicates a server error. 404 indicates the resource isn't found, which is what you're describing. There is no server error, just an incorrect URL.


If the user enters the wrong script name, it should be 501 (or maybe 500). If they enter the wrong image identifier, it should be 404 since there is simply no corresponding resource.


404 file not found is clearly the obvious decision.

Or 400, bad request because they requested an identifier that did not exist.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜