added handling of http errors and timeouts