File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -9,7 +9,10 @@ class GraphQLLocatedError(GraphQLError):
9
9
10
10
def __init__ (self , nodes , original_error = None ):
11
11
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' )
13
16
else :
14
17
message = 'An unknown error occurred.'
15
18
Original file line number Diff line number Diff line change
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 )
You can’t perform that action at this time.
0 commit comments