improve error handling for bad server response

This commit is contained in:
William Kray 2021-06-08 08:11:15 -07:00
parent 15840f89de
commit 3307eaf2cd
2 changed files with 7 additions and 2 deletions

View File

@ -69,9 +69,14 @@ class Invite(Plugin):
try:
response = await self.http.post(f"{self.config['api_url']}/token", headers=headers, \
json={"max_usage": 1, "one_time": True, "ex_date": ex_date, "expiration_date": ex_date})
status = response.status
resp_json = await response.json()
except Exception as e:
await evt.respond(f"request failed: {e.message}")
body = await response.text()
await evt.respond(f"Uh oh! I got a {status} response from your registration endpoint:<br /> \
{body}<br /> \
which prompted me to produce this error:<br /> \
<code>{e.message}</code>", allow_html=True)
return None
try:
token = resp_json['name']

View File

@ -1,6 +1,6 @@
maubot: 0.1.0
id: org.jobmachine.invitebot
version: 0.3.0
version: 0.3.1
license: MIT
modules:
- invite