diff --git a/swiss_locator/core/profiles/profile_generator.py b/swiss_locator/core/profiles/profile_generator.py index ff041f0..ff34825 100644 --- a/swiss_locator/core/profiles/profile_generator.py +++ b/swiss_locator/core/profiles/profile_generator.py @@ -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 diff --git a/swiss_locator/swiss_locator_plugin.py b/swiss_locator/swiss_locator_plugin.py index 6acd821..994c5c8 100644 --- a/swiss_locator/swiss_locator_plugin.py +++ b/swiss_locator/swiss_locator_plugin.py @@ -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: @@ -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 (