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