Question

By default, the HTTP response code for "file not found" has always been 404. I never really thought about it until recently someone was saying that if the missing file is part of an application then the response should be 500 (internal server error) because it's not a client error (4xx error class). The example for that situation was when the deployment for media files failed.

So, in that situation, should the status be 404 or 500? If it's 404, what is the reason for that situation?

Was it helpful?

Solution

Technically, if there's never a reason why this file should be unavailable when your application is configured and running properly, you probably should return a 500 (or 500 class error). It's an unexpected server side issue.

In practice, however, it's typical to use a 404 here because that's what web servers tend to do on static file retrieval. I wouldn't spend a lot of time on trying to fix this unless there's some meaningful impact either way.

OTHER TIPS

As far as I understand it, there is no way to know that "missing file is part of an application". Client comes with some URL "https://example.com/foo", and the "foo" is just not there. Was it client mistake of application improperly installed? You don't know, but generally you assume that the first is more probable. So it's 404. If you verify path some other way, and conclude that the path would be working if you install the application properly, then you can return some 5xx status, for example "503 Service Unavailable";

Licensed under: CC-BY-SA with attribution
scroll top