Fix inconsistent behavior in 404/500 handling