Improve handling of http errors