Skip to content

Commit

Permalink
Add more error case coverage for Nextcloud identification
Browse files Browse the repository at this point in the history
  • Loading branch information
LoanR committed Apr 26, 2024
1 parent 74ea767 commit 7bb28e8
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion web/b3desk/models/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ def make_nextcloud_credentials_request(url, payload, headers):
return None


class MissingToken(Exception):
"""Exception raised if unable to get token.
Attributes:
message -- explanation of the error
"""

def __init__(self, message="No token given for the B3Desk instance"):
self.message = message
super().__init__(self.message)


class TooManyUsers(Exception):
"""Exception raised if email returns more than one user.
Expand Down Expand Up @@ -101,7 +113,15 @@ def get_secondary_identity_provider_id_from_email(email):
"Get token request error: %s, %s", exception, token_response.text
)
raise exception
access_token = token_response.json()["access_token"]

try:
access_token = token_response.json()["access_token"]
if not access_token:
raise MissingToken(
f"No token given for the B3Desk instance, {token_response}"
)
except (AttributeError, KeyError):
raise MissingToken(f"No token given for the B3Desk instance, {token_response}")

try:
users_response = get_secondary_identity_provider_users_from_email(
Expand Down

0 comments on commit 7bb28e8

Please sign in to comment.