diff --git a/core/modules/sms.py b/core/modules/sms.py index 0c076cf..584a8bc 100644 --- a/core/modules/sms.py +++ b/core/modules/sms.py @@ -4,6 +4,10 @@ from django.conf import settings from dbsettings.functions import getValue +import logging + +logger = logging.getLogger(__name__) + providers = [] modules_available = [] @@ -17,22 +21,31 @@ for module in settings.EXPEPHALON_MODULES: modules_available.append(mos.CREATE) except (AttributeError, ModuleNotFoundError): continue + except Exception as e: + logger.error("Error importing SMS module {module}: {e}") def get_sms_provider_by_name(name, active=False): for provider in providers: - if provider.get_name == name and (provider.is_active or not active): - return provider + try: + if provider.get_name == name: + if provider.is_active or not active: + return provider + except Exception as e: + logger.error("Error checking SMS module {provider.get_name}: {e}") -def get_default_sms_provider_name(): - return getValue("core.sms.default", False) +def get_default_sms_provider_name(default=False): + return getValue("core.sms.default", default) -def get_default_sms_provider(): - provider = get_sms_provider_by_name(get_default_sms_provider_name(), True) +def get_default_sms_provider(active=True): + provider = get_sms_provider_by_name(get_default_sms_provider_name(), active) if provider: return provider for provider in providers: - if provider.is_active: - return provider + try: + if provider.is_active or not active: + return provider + except Exception as e: + logger.error("Error checking SMS module {provider.get_name}: {e}") - raise RuntimeError("No SMS provider is currently active") \ No newline at end of file + raise RuntimeError("No SMS provider is currently active")