chore(messaging.backends): better error messages

pull/1/head
Luca 8 months ago
parent 567b4cdf83
commit af59a6d393

@ -22,16 +22,21 @@ class Configuration(BaseConfiguration):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
for setting in (
"clicksend_password",
"clicksend_sender_id",
"clicksend_username",
):
try:
settings.SMS_SETTINGS[setting]
except KeyError:
raise ImproperlyConfigured(
f"'{setting}' must be set in SMS_SETTINGS for ClickSend backend"
)
self.username = settings.SMS_SETTINGS["clicksend_username"] self.username = settings.SMS_SETTINGS["clicksend_username"]
self.password = settings.SMS_SETTINGS["clicksend_password"] self.password = settings.SMS_SETTINGS["clicksend_password"]
try:
settings.SMS_SETTINGS["clicksend_sender_id"]
except KeyError:
raise ImproperlyConfigured(
"'clicksend_sender_id' must be set in SMS_SETTINGS for ClickSend backend"
)
client = ApiClient(Configuration()) client = ApiClient(Configuration())
@ -45,6 +50,8 @@ class Receiver(BaseReceiver):
except ValueError: except ValueError:
raise ValueError("invalid timestamp") raise ValueError("invalid timestamp")
if not kwargs.get("from", ""):
raise ValueError("message has no sender")
if not message_id: if not message_id:
raise ValueError("empty message id") raise ValueError("empty message id")

@ -12,7 +12,15 @@ __all__ = ("Receiver", "Sender")
BASE_URL = "https://api.sipgate.com/v2" BASE_URL = "https://api.sipgate.com/v2"
auth = HTTPBasicAuth( inbound_auth = HTTPBasicAuth(
settings.SMS_SETTINGS.get(
"sipgate_incoming_token_id", settings.SIPGATE_INCOMING_TOKEN_ID
),
settings.SMS_SETTINGS.get(
"sipgate_incoming_token", settings.SIPGATE_INCOMING_TOKEN
),
)
outbound_auth = HTTPBasicAuth(
settings.SMS_SETTINGS.get("sipgate_token_id", settings.SIPGATE_TOKEN_ID), settings.SMS_SETTINGS.get("sipgate_token_id", settings.SIPGATE_TOKEN_ID),
settings.SMS_SETTINGS.get("sipgate_token", settings.SIPGATE_TOKEN), settings.SMS_SETTINGS.get("sipgate_token", settings.SIPGATE_TOKEN),
) )
@ -41,7 +49,9 @@ class Receiver(BaseReceiver):
total = 10 total = 10
while offset < total: while offset < total:
r = requests.get( r = requests.get(
f"{BASE_URL}/history", auth=auth, params=params | {"offset": offset} f"{BASE_URL}/history",
auth=inbound_auth,
params=params | {"offset": offset},
) )
r.raise_for_status() r.raise_for_status()
@ -69,7 +79,7 @@ class Sender(BaseSender):
for message in messages: for message in messages:
r = requests.post( r = requests.post(
f"{BASE_URL}/sessions/sms", f"{BASE_URL}/sessions/sms",
auth=auth, auth=outbound_auth,
json={ json={
"smsId": settings.SMS_SETTINGS.get( "smsId": settings.SMS_SETTINGS.get(
"sipgate_sms_extension", settings.SIPGATE_SMS_EXTENSION "sipgate_sms_extension", settings.SIPGATE_SMS_EXTENSION

Loading…
Cancel
Save