Skip to content

Commit

Permalink
Enhance HTTP errors handling for XYZTiles
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexeyPechnikov committed Mar 6, 2024
1 parent f114508 commit 97c3ab1
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pygmtsar/pygmtsar/XYZTiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,15 @@ def download_tile(url, x, y, z, debug=False):
if debug:
print('DEBUG: XYZTiles: url', url_tile)
response = requests.get(url_tile, headers=self.headers, timeout=self.http_timeout)
image = iio.imread(io.BytesIO(response.content))
return image
if response.status_code == 200:
# Check if the content type is an image
if 'image' in response.headers.get('Content-Type', ''):
image = iio.imread(io.BytesIO(response.content))
return image
else:
raise ValueError(f'Expected an image response, got {response.headers.get("Content-Type")}')
else:
raise ValueError(f'Request for tile {url_tile} failed with status {response.status_code}')

def num2deg(xtile, ytile, zoom):
n = 2.0 ** zoom
Expand Down

0 comments on commit 97c3ab1

Please sign in to comment.