Improve http error handling