Improve 500 error response handling