From 90cdaf07fdd75f036521222d92d8c72482562817 Mon Sep 17 00:00:00 2001 From: Taher Chegini Date: Fri, 9 Aug 2024 10:23:43 -0700 Subject: [PATCH] ENH: When the CRS of a WMS cannot be parsed throw a more informative error regarding the service being down (addresses https://github.com/hyriver/pygeohydro/issues/122) [skip ci] --- src/pygeoogc/utils.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/pygeoogc/utils.py b/src/pygeoogc/utils.py index 5d87264..1243375 100644 --- a/src/pygeoogc/utils.py +++ b/src/pygeoogc/utils.py @@ -42,7 +42,7 @@ import async_retriever as ar from pygeoogc import cache_keys -from pygeoogc.exceptions import InputTypeError, InputValueError, ServiceError +from pygeoogc.exceptions import InputTypeError, InputValueError, ServiceError, ServiceUnavailableError if TYPE_CHECKING: from typing_extensions import Self @@ -853,7 +853,10 @@ def get_path(tag_list: list[str]) -> str: return f"/{{{ns}}}".join(["", *tag_list])[1:] kwds = {"params": {"service": "wms", "request": "GetCapabilities"}} - root = ETree.fromstring(ar.retrieve_text([url], [kwds], ssl=False)[0]) + try: + root = ETree.fromstring(ar.retrieve_text([url], [kwds], ssl=False)[0]) + except ETree.ParseError as ex: + raise ServiceUnavailableError(url) from ex return [ t.text.lower() # pyright: ignore[reportOptionalMemberAccess] for t in root.findall(get_path(["Capability", "Layer", "CRS"]))