Skip to content

Commit

Permalink
Merge pull request #470 from kids-first/referral-token-exceptions
Browse files Browse the repository at this point in the history
🐛 Fix referral token exceptions
  • Loading branch information
dankolbman authored Sep 2, 2020
2 parents 354a8a6 + 4738147 commit e8ad9d5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion creator/referral_tokens/mutations.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import graphene
import uuid
from datetime import timedelta
from django.conf import settings
from django.contrib.auth.models import Group
from django.core.mail import send_mail
from django.core.exceptions import ValidationError
from django.template.loader import render_to_string
from django.utils import timezone
from graphql import GraphQLError
Expand Down Expand Up @@ -172,7 +174,7 @@ def mutate(self, info, token):
try:
_, uuid = from_global_id(token)
referral_token = ReferralToken.objects.get(uuid=uuid)
except ReferralToken.DoesNotExist:
except (ReferralToken.DoesNotExist, ValidationError):
raise GraphQLError("Referral token does not exist.")

if not referral_token.is_valid:
Expand Down
6 changes: 4 additions & 2 deletions creator/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ def format_error(error):
FileUploadGraphQLView, FileUploadGraphQLView
).format_error(error)

if hasattr(error, "original_error") and isinstance(
error.original_error, ValidationError
if (
hasattr(error, "original_error")
and isinstance(error.original_error, ValidationError)
and hasattr(error.original_error, "error_dict")
):
error_dict = error.original_error.error_dict
if "__all__" in error_dict:
Expand Down

0 comments on commit e8ad9d5

Please sign in to comment.