Make things a lil more robust to voipms errors

This commit is contained in:
Alicia
2024-05-08 23:39:37 -07:00
parent 3051df7a0d
commit 93957dfc80
2 changed files with 12 additions and 5 deletions

View File

@@ -59,8 +59,11 @@ class Gateway(BaseGateway):
}) as response:
# For whatever cursed reason, this call sometimes returns with
# text/html as the content type, so we disable the check
json = await response.json(content_type=None)
if json['status'] == 'success':
return
else:
raise XMPPError("Received error from voipms")
try:
json = await response.json(content_type=None)
if json['status'] == 'success':
return
else:
raise XMPPError("Received error from voipms")
except:
raise XMPPError("Failure decoding response from voipms")

View File

@@ -92,6 +92,7 @@ class Session(BaseSession[str, Contact]):
'all_messages': 1,
'content_type': 'json',
}) as response:
try:
json = await response.json()
log.debug(f"received messages from voipms {json}")
@@ -99,6 +100,9 @@ class Session(BaseSession[str, Contact]):
return []
else:
return json['sms']
except client_exceptions.ContentTypeError:
log.warning("Received non-json response from voipms")
return []
async def on_file(self, chat: Contact, url: str, **_kwargs):
f = self.user.registration_form