Skip to content

Commit 5474674

Browse files
authored
Merge pull request #92 from romulorosa/rrf-handle-unicode-exception-message
fix(graphene)handle unicode exception message
2 parents a8c01ee + d978405 commit 5474674

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

graphql/error/located_error.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ class GraphQLLocatedError(GraphQLError):
99

1010
def __init__(self, nodes, original_error=None):
1111
if original_error:
12-
message = str(original_error)
12+
try:
13+
message = str(original_error)
14+
except UnicodeEncodeError:
15+
message = original_error.message.encode('utf-8')
1316
else:
1417
message = 'An unknown error occurred.'
1518

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# coding: utf-8
2+
3+
from graphql import GraphQLField
4+
from graphql import GraphQLObjectType
5+
from graphql import GraphQLSchema
6+
from graphql import GraphQLString
7+
from graphql import execute
8+
from graphql import parse
9+
from graphql.error import GraphQLLocatedError
10+
11+
12+
def test_unicode_error_message():
13+
ast = parse('query Example { unicode }')
14+
15+
def resolver(context, *_):
16+
raise Exception(u'UNIÇODÉ!')
17+
18+
Type = GraphQLObjectType('Type', {
19+
'unicode': GraphQLField(GraphQLString, resolver=resolver),
20+
})
21+
22+
result = execute(GraphQLSchema(Type), ast)
23+
assert isinstance(result.errors[0], GraphQLLocatedError)

0 commit comments

Comments
 (0)