Skip to content

Commit

Permalink
add try/except around slack channel updates to handle keyerror when t… (
Browse files Browse the repository at this point in the history
#16)

* add try/except around slack channel updates to handle keyerror when the bot is not allowed or channel is archived

* move error handling to initial get channel call to catch errors where the channel id cannot be found

* change payload[channel] to just channel cause its clear and less letters
  • Loading branch information
jessica-ritter authored Oct 22, 2019
1 parent e01ce31 commit ed37edf
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lambda/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,12 @@ def get_slack_topic(channel):
Names=[os.environ['SLACK_API_KEY_NAME']],
WithDecryption=True)['Parameters'][0]['Value']
payload['channel'] = channel
r = requests.post('https://slack.com/api/conversations.info', data=payload)
current = r.json()['channel']['topic']['value']
logger.debug("Current Topic: '{}'".format(current))
try:
r = requests.post('https://slack.com/api/conversations.info', data=payload)
current = r.json()['channel']['topic']['value']
logger.debug("Current Topic: '{}'".format(current))
except KeyError:
logger.critical("Could not find '{}' on slack, has the on-call bot been removed from this channel?".format(channel))
return current


Expand Down

0 comments on commit ed37edf

Please sign in to comment.