summaryrefslogtreecommitdiff
path: root/cdsapi
diff options
context:
space:
mode:
authorBaudouin Raoult <baudouin.raoult@ecmwf.int>2018-05-23 11:03:31 +0100
committerBaudouin Raoult <baudouin.raoult@ecmwf.int>2018-05-23 11:03:31 +0100
commitbc0e0537deeac7adfbcf1e0f8bc9a28adde334d3 (patch)
tree8004c40abde5f203a60ff2577f8e8119d165be74 /cdsapi
parente791c4fbf4efe857981f175641a976bae3f5681e (diff)
more checks
Diffstat (limited to 'cdsapi')
-rw-r--r--cdsapi/api.py19
1 files changed, 13 insertions, 6 deletions
diff --git a/cdsapi/api.py b/cdsapi/api.py
index 0ada51b..3f3be34 100644
--- a/cdsapi/api.py
+++ b/cdsapi/api.py
@@ -205,7 +205,7 @@ class Client(object):
if n.strip() == '' and not self.full_stack:
break
self.logger.error(" %s", n)
- raise Exception(reply['error'].get('reason'))
+ raise Exception("%s. %s." % (reply['error'].get('message'), reply['error'].get('reason')))
raise Exception('Unknown API state [%s]' % (reply['state'],))
@@ -226,14 +226,21 @@ class Client(object):
def wrapped(*args, **kwargs):
tries = 0
while tries < self.retry_max:
- r = call(*args, **kwargs)
- if not retriable(r.status_code, r.reason):
- return r
+ try:
+ r = call(*args, **kwargs)
+ except requests.exceptions.ConnectionError as e:
+ r = None
+ self.logger.warning("Recovering from connection error [%s], attemps %s of %s",
+ e, tries, self.retry_max)
+
+ if r is not None:
+ if not retriable(r.status_code, r.reason):
+ return r
+ self.logger.warning("Recovering from HTTP error [%s %s], attemps %s of %s",
+ r.status_code, r.reason, tries, self.retry_max)
tries += 1
- self.logger.warning("Recovering from HTTP error [%s %s], attemps %s of %s",
- r.status_code, r.reason, tries, self.retry_max)
self.logger.warning("Retrying in %s second (", self.sleep_max)
time.sleep(self.sleep_max)