Skip to content

Commit

Permalink
Check QGIS >= 3.37 to subclass profile sources (before that version, …
Browse files Browse the repository at this point in the history
…even if we can subclass it, we won't be able to register it anyways); handle exceptions when reading service responses
  • Loading branch information
gacarrillor committed May 1, 2024
1 parent cab8b39 commit 4227938
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
9 changes: 8 additions & 1 deletion swiss_locator/core/profiles/profile_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,14 @@ def url_with_param(url, params) -> str:
result = {"error": reply.errorString()}
else:
content = reply.content()
result = json.loads(str(content, 'utf-8'))
try:
result = json.loads(str(content, 'utf-8'))
except json.decoder.JSONDecodeError as e:
QgsMessageLog.logMessage(
"Unable to parse results from Profile service. Details: {}".format(e.msg),
"Swiss locator",
Qgis.Critical
)

return result

Expand Down
11 changes: 9 additions & 2 deletions swiss_locator/swiss_locator_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@
SwissLocatorFilterLocation,
)
from swiss_locator.core.filters.swiss_locator_filter_wmts import SwissLocatorFilterWMTS
from swiss_locator.core.profiles.profile_generator import SwissProfileSource
try:
from swiss_locator.core.profiles.profile_generator import SwissProfileSource
except ImportError:
# Should fail only for QGIS < 3.26, where profiles weren't available
SwissProfileSource = None


class SwissLocatorPlugin:
Expand All @@ -50,7 +54,10 @@ def __init__(self, iface: QgisInterface):
QCoreApplication.installTranslator(self.translator)

self.locator_filters = []
self.profile_source = SwissProfileSource()

if Qgis.QGIS_VERSION_INT >= 33700:
# Only on QGIS 3.37+ we'll be able to register profile sources
self.profile_source = SwissProfileSource()

def initGui(self):
for _filter in (
Expand Down

0 comments on commit 4227938

Please sign in to comment.