Return correct error code when file is missing

So far there wasn't a check if the returned error when opening a file is indicating that the file doesn't exist. If it doesn't exist we want to return 404 instead of 500 as it communicates more clearly.