improve error handling for http errors