Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
#393 better error handling for network connection problems
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzysztof (Chris) Bernat committed Oct 3, 2017
1 parent f5c74b8 commit 3396076
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions cate/ds/esa_cci_odp.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ def _fetch_solr_json(base_url, query_args, offset=0, limit=3500, timeout=10, mon
# noinspection PyArgumentList
paging_query_args.update(offset=offset, limit=limit, format='application/solr+json')
url = base_url + '?' + urllib.parse.urlencode(paging_query_args)
with urllib.request.urlopen(url, timeout=timeout) as response:
try:
try:
with urllib.request.urlopen(url, timeout=timeout) as response:
json_text = response.read()
json_dict = json.loads(json_text.decode('utf-8'))
if num_found is -1:
Expand All @@ -166,12 +166,12 @@ def _fetch_solr_json(base_url, query_args, offset=0, limit=3500, timeout=10, mon
combined_json_dict.get('response', {}).get('docs', []).extend(docs)
if num_found < offset + limit:
break
except (urllib.error.HTTPError, urllib.error.URLError) as error:
raise DataAccessError(None, "Open Data Portal index download failed, {}\n{}"
.format(error, base_url))
except socket.timeout:
raise DataAccessError(None, "Open Data Portal index download failed, connection timeout\n{}"
.format(base_url))
except (urllib.error.HTTPError, urllib.error.URLError) as error:
raise DataAccessError(None, "Open Data Portal index download failed, {}\n{}"
.format(error, base_url))
except socket.timeout:
raise DataAccessError(None, "Open Data Portal index download failed, connection timeout\n{}"
.format(base_url))
offset += limit
return combined_json_dict

Expand Down

0 comments on commit 3396076

Please sign in to comment.