Skip to content

Commit 1a5db7e

Browse files
committed
Replace Exception with GraphQLError
1 parent 8b611ca commit 1a5db7e

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

hackernews/hackernews/schema.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import graphql_jwt
33
from graphene_django import DjangoObjectType
44
from django.contrib.auth import get_user_model
5+
from graphql import GraphQLError
56

67
from links.models import Link as LinkModel
78
from links.models import Vote
@@ -35,7 +36,7 @@ class Arguments:
3536
def mutate(self, info, url, description):
3637
user = info.context.user
3738
if user.is_anonymous:
38-
raise Exception("Anonymous users can't create links!")
39+
raise GraphQLError("Anonymous users can't create links!")
3940
link = LinkModel(url=url, description=description, posted_by=user)
4041
link.save()
4142

@@ -57,10 +58,10 @@ class Arguments:
5758
def mutate(self, info, linkId):
5859
user = info.context.user
5960
if user.is_anonymous:
60-
raise Exception("You must be logged in to vote!")
61+
raise GraphQLError("You must be logged in to vote!")
6162
link = LinkModel.objects.filter(id=linkId).first()
6263
if link is None:
63-
raise Exception(f"The link ={linkId} is invalid.")
64+
raise GraphQLError(f"The link ={linkId} is invalid.")
6465

6566
Vote.objects.create(user=user, link=link)
6667

@@ -113,7 +114,7 @@ def resolve_users(self, info):
113114
def resolve_whoami(self, info):
114115
user = info.context.user
115116
if user.is_anonymous:
116-
raise Exception("Not logged in!")
117+
raise GraphQLError("Not logged in!")
117118
return user
118119

119120

0 commit comments

Comments
 (0)