Skip to content

Commit

Permalink
Merge pull request #198 from MeganerdDev/patch-1
Browse files Browse the repository at this point in the history
Improve visibility for access_key token exception in get_token()
  • Loading branch information
smk4664 authored May 31, 2023
2 parents ff4fab4 + d790829 commit 89385bc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions changes/197.added
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a try/except block and error logger message when access_token missing from get_token() response.
13 changes: 12 additions & 1 deletion nautobot_chatops/dispatchers/ms_teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,18 @@ def get_token():
},
timeout=15,
)
token = response.json()["access_token"]
logger.debug("DEBUG: get_token() response %s", response.json())
try:
token = response.json()["access_token"]
except KeyError as exc:
logger.error(
"get_token() response is missing access_token, which indicates an error authenticating with MS Teams."
"Check the app_id and app_secret."
)
raise KeyError(
"get_token() response is missing access_token, which indicates an error authenticating with MS Teams."
"Check the app_id and app_secret."
) from exc
return token

def _send(self, content, content_type="message"):
Expand Down

0 comments on commit 89385bc

Please sign in to comment.