Added some error handling for HTTP responses.