From 3307eaf2cdcf72133ce70288e2ac0b98133d9533 Mon Sep 17 00:00:00 2001 From: William Kray Date: Tue, 8 Jun 2021 08:11:15 -0700 Subject: [PATCH] improve error handling for bad server response --- invite.py | 7 ++++++- maubot.yaml | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/invite.py b/invite.py index b71ac5a..a2c9a67 100644 --- a/invite.py +++ b/invite.py @@ -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:
\ + {body}
\ + which prompted me to produce this error:
\ + {e.message}", allow_html=True) return None try: token = resp_json['name'] diff --git a/maubot.yaml b/maubot.yaml index 5b3283c..2c6261f 100644 --- a/maubot.yaml +++ b/maubot.yaml @@ -1,6 +1,6 @@ maubot: 0.1.0 id: org.jobmachine.invitebot -version: 0.3.0 +version: 0.3.1 license: MIT modules: - invite