Skip to content

Commit

Permalink
Add an error message when GADM server is down (#890)
Browse files Browse the repository at this point in the history
* Add an error message when GADM server is down

* Fix a timeout value

* Improve logging

* Replace logging with exception message
  • Loading branch information
ekatef committed Oct 18, 2023
1 parent f7eb5e4 commit 0d082c3
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion scripts/build_shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,19 @@ def download_GADM(country_code, update=False, out_logging=False):
# create data/osm directory
os.makedirs(os.path.dirname(GADM_inputfile_gpkg), exist_ok=True)

with requests.get(GADM_url, stream=True) as r:
try:
r = requests.get(GADM_url, stream=True, timeout=300)
except (requests.exceptions.ConnectionError, requests.exceptions.Timeout):
raise Exception(
f"GADM server is down at {GADM_url}. Data needed for building shapes can't be extracted.\n\r"
)
except Exception as exception:
raise Exception(
f"An error happened when trying to load GADM data by {GADM_url}.\n\r"
+ str(exception)
+ "\n\r"
)
else:
with open(GADM_inputfile_gpkg, "wb") as f:
shutil.copyfileobj(r.raw, f)

Expand Down

0 comments on commit 0d082c3

Please sign in to comment.