Correctly handle 404s and 500s in the server