Skip to content

Commit

Permalink
improved exception handling for unexpected and malformed messages
Browse files Browse the repository at this point in the history
  • Loading branch information
m3dwards authored and gkrizek committed Feb 20, 2022
1 parent 6a7d0ff commit 85fa507
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
7 changes: 4 additions & 3 deletions ghi/ghimastodon.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ def login(pool):
def sendToots(pool, messages):
try:
mastodon = login(pool)

for message in messages:
mastodon.toot(message)

except MastodonIllegalArgumentError as e:
errorMessage = "Mastodon - Probably the password for Mastodon in the configfile is not correct"
logging.error(errorMessage)
Expand All @@ -83,9 +87,6 @@ def sendToots(pool, messages):
})
}

try:
for message in messages:
mastodon.toot(message)
except Exception as e:
errorMessage = "Mastodon - There was a problem sending messages to Mastodon"
logging.error(errorMessage)
Expand Down
24 changes: 15 additions & 9 deletions ghi/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,21 @@ def start_workers(self):

def worker(self):
while True:
item, args, kwargs = self.get()
logging.info("Start UUID: %s" % args[0]['uuid'])
logging.info("{} {} ({})".format(args[0]['httpMethod'], args[0]['path'], args[0]['requesterIp']))
response = item(*args, **kwargs)
logging.info("")
logging.info("Response:")
logging.info(response)
logging.info("Stop UUID: %s" % args[0]['uuid'])
logging.info("")
try:
item, args, kwargs = self.get()
logging.info("Start UUID: %s" % args[0]['uuid'])
logging.info("{} {} ({})".format(args[0]['httpMethod'], args[0]['path'], args[0]['requesterIp']))
response = item(*args, **kwargs)
logging.info("")
logging.info("Response:")
logging.info(response)
logging.info("Stop UUID: %s" % args[0]['uuid'])
logging.info("")
except Exception as e:
errorMessage = "Unexpected problem processing request"
logging.error(errorMessage)
logging.info(e)

self.task_done()
sleep(0.5)

Expand Down

0 comments on commit 85fa507

Please sign in to comment.