Skip to content

Commit

Permalink
Better error on error code
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Mar 10, 2023
1 parent 5b499bd commit 0134a46
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions geoportal/c2cgeoportal_geoportal/lib/lingua_extractor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2011-2022, Camptocamp SA
# Copyright (c) 2011-2023, Camptocamp SA
# All rights reserved.

# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -770,21 +770,36 @@ def _layer_attributes(self, url: str, layer: str) -> Tuple[List[str], List[str]]
]
)
print(f"Get WMS GetCapabilities for URL {wms_getcap_url},\nwith headers: {rendered_headers}")
response = requests.get(wms_getcap_url, headers=headers, **kwargs)
response = requests.get( # pylint: disable=missing-timeout
wms_getcap_url, headers=headers, **kwargs
)

try:
self.wms_capabilities_cache[url] = WebMapService(None, xml=response.content)
except Exception as e:
if response.ok:
try:
self.wms_capabilities_cache[url] = WebMapService(None, xml=response.content)
except Exception as e:
print(
colorize(
"ERROR! an error occurred while trying to parse "
"the GetCapabilities document.",
Color.RED,
)
)
print(colorize(str(e), Color.RED))
print(f"URL: {wms_getcap_url}\nxml:\n{response.text}")
if _get_config_str("IGNORE_I18N_ERRORS", "FALSE") != "TRUE":
raise
else:
print(
colorize(
"ERROR! an error occurred while trying to parse the GetCapabilities document.",
f"ERROR! Unable to GetCapabilities from URL: {wms_getcap_url},\n"
f"with headers: {rendered_headers}",
Color.RED,
)
)
print(colorize(str(e), Color.RED))
print(f"URL: {wms_getcap_url}\nxml:\n{response.text}")
print(f"Response: {response.status_code} {response.reason}\n{response.text}")
if _get_config_str("IGNORE_I18N_ERRORS", "FALSE") != "TRUE":
raise
raise Exception(response.reason)
except Exception as e:
print(colorize(str(e), Color.RED))
rendered_headers = " ".join(
Expand Down Expand Up @@ -823,7 +838,9 @@ def _layer_attributes(self, url: str, layer: str) -> Tuple[List[str], List[str]]
.url()
)
try:
response = requests.get(wfs_describe_feature_url, headers=headers, **kwargs)
response = requests.get( # pylint: disable=missing-timeout
wfs_describe_feature_url, headers=headers, **kwargs
)
except Exception as e:
print(colorize(str(e), Color.RED))
print(
Expand Down Expand Up @@ -859,7 +876,7 @@ def _layer_attributes(self, url: str, layer: str) -> Tuple[List[str], List[str]]
except ExpatError as e:
print(
colorize(
"ERROR! an error occurred while trying to " "parse the DescribeFeatureType document.",
"ERROR! an error occurred while trying to parse the DescribeFeatureType document.",
Color.RED,
)
)
Expand Down

0 comments on commit 0134a46

Please sign in to comment.