File tree 2 files changed +16
-3
lines changed 2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change 1
- from six import text_type
2
-
3
1
from .base import GraphQLError
4
2
5
3
# Necessary for static type checking
9
7
10
8
def format_error (error ):
11
9
# type: (Exception) -> Dict[str, Any]
12
- formatted_error = {"message" : text_type (error )} # type: Dict[str, Any]
10
+ try :
11
+ message = str (error )
12
+ except UnicodeEncodeError :
13
+ message = error .message .encode ("utf-8" ) # type: ignore
14
+ formatted_error = {"message" : message } # type: Dict[str, Any]
13
15
if isinstance (error , GraphQLError ):
14
16
if error .locations is not None :
15
17
formatted_error ["locations" ] = [
Original file line number Diff line number Diff line change
1
+ # coding: utf-8
2
+ from graphql .error import GraphQLError , format_error
3
+
4
+
5
+ def test_unicode_format_error ():
6
+ # type: () -> None
7
+ e = GraphQLError ("UNIÇODÉ!" )
8
+ assert isinstance (format_error (e ), dict )
9
+
10
+ e = GraphQLError ("\xd0 \xbe \xd1 \x88 \xd0 \xb8 \xd0 \xb1 \xd0 \xba \xd0 \xb0 " )
11
+ assert isinstance (format_error (e ), dict )
You can’t perform that action at this time.
0 commit comments