diff --git a/src/geoapis/raster.py b/src/geoapis/raster.py index 477e9f4..a340aaf 100644 --- a/src/geoapis/raster.py +++ b/src/geoapis/raster.py @@ -149,12 +149,13 @@ def run(self, layer: int) -> pathlib.Path: url=f"{self.base_url}/exports/", headers=headers, json=api_query ) json_query = response.json() - if not json_query["is_valid"]: - logging.warning( - "Invalid initial query. Check layer exists and is within bounds. " - f"json_query['invalid_reasons']: {json_query['invalid_reasons']}. " - f"json_query['items'][0]['invalid_reasons']: {json_query['items'][0]['invalid_reasons']}" - ) + if "is_valid" in json_query.keys() and not json_query["is_valid"]: + message = f"Invalid initial query. Check layer {layer} exists and is within bounds." + if "invalid_reasons" in json_query.keys(): + message = message + f" json_query['invalid_reasons']: {json_query['invalid_reasons']}." + if "items" in json_query.keys(): + message = message + f" json_query['items'][0]['invalid_reasons']: {json_query['items'][0]['invalid_reasons']}" + logging.warning(message) return [] query_id = json_query["id"]