Skip to content

Commit

Permalink
fix: gracefully handle DoesNotExist exceptions for tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
rohan-chaturvedi committed Dec 11, 2024
1 parent 2539f77 commit 4a5e16a
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions backend/api/utils/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,22 @@ def token_is_expired_or_deleted(auth_token):
prefix, token_type, token_value = auth_token.split(" ")

if token_type == "User":
token = UserToken.objects.get(token=token_value)
try:
token = UserToken.objects.get(token=token_value)
except UserToken.DoesNotExist:
return True

elif token_type == "Service":
token = ServiceToken.objects.get(token=token_value)
try:
token = ServiceToken.objects.get(token=token_value)
except ServiceToken.DoesNotExist:
return True

elif token_type == "ServiceAccount":
token = ServiceAccountToken.objects.get(token=token_value)
try:
token = ServiceAccountToken.objects.get(token=token_value)
except ServiceAccountToken.DoesNotExist:
return True

return token.deleted_at is not None or (
token.expires_at is not None and token.expires_at < timezone.now()
Expand Down

0 comments on commit 4a5e16a

Please sign in to comment.