Add error handling.

This commit is contained in:
Sergey Vartanov 2021-09-26 09:12:43 +03:00
parent c0b4d35573
commit a588a0c82e
2 changed files with 13 additions and 1 deletions

View file

@ -42,6 +42,18 @@ def get_osm(
{"bbox": boundary_box.get_format()},
)
if not content.startswith(b"<"):
if content == (
b"You requested too many nodes (limit is 50000). Either request a "
b"smaller area, or use planet.osm"
):
raise NetworkError(
"Cannot download data: too many nodes (limit is 50000). Try "
"to request smaller area."
)
else:
raise NetworkError("Cannot download data.")
with cache_file_path.open("bw+") as output_file:
output_file.write(content)