@@ -28,38 +28,18 @@ def __init__(self, code, message=None, info=None, http_response=None):
28
28
super (ApiException , self ).__init__ (message )
29
29
self .message = message
30
30
self .code = code
31
- self .info = info
32
31
self .http_response = http_response
33
32
self .global_transaction_id = None
34
33
if http_response is not None :
35
34
self .global_transaction_id = http_response .headers .get ('X-Global-Transaction-ID' )
36
- self .info = self .info if self .info else self ._get_error_info (http_response )
37
35
self .message = self .message if self .message else self ._get_error_message (http_response )
38
36
39
37
def __str__ (self ):
40
38
msg = 'Error: ' + str (self .message ) + ', Code: ' + str (self .code )
41
- if self .info is not None :
42
- msg += ' , Information: ' + str (self .info )
43
39
if self .global_transaction_id is not None :
44
40
msg += ' , X-global-transaction-id: ' + str (self .global_transaction_id )
45
41
return msg
46
42
47
- def _get_error_info (self , response ):
48
- """
49
- Gets the error info (if any) from a JSON response.
50
- :return: A `dict` containing additional information about the error.
51
- :rtype: dict
52
- """
53
- info_keys = ['code_description' , 'description' , 'errors' , 'help' ,
54
- 'sub_code' , 'warnings' ]
55
- error_info = {}
56
- try :
57
- error_json = response .json ()
58
- error_info = {k :v for k , v in error_json .items () if k in info_keys }
59
- except :
60
- pass
61
- return error_info if any (error_info ) else None
62
-
63
43
def _get_error_message (self , response ):
64
44
"""
65
45
Gets the error message from a JSON response.
@@ -69,20 +49,14 @@ def _get_error_message(self, response):
69
49
error_message = 'Unknown error'
70
50
try :
71
51
error_json = response .json ()
72
- if 'error' in error_json :
73
- if isinstance (error_json ['error' ], dict ) and 'description' in \
74
- error_json ['error' ]:
75
- error_message = error_json ['error' ]['description' ]
76
- else :
77
- error_message = error_json ['error' ]
78
- elif 'error_message' in error_json :
79
- error_message = error_json ['error_message' ]
80
- elif 'errorMessage' in error_json :
81
- error_message = error_json ['errorMessage' ]
82
- elif 'msg' in error_json :
83
- error_message = error_json ['msg' ]
84
- elif 'statusInfo' in error_json :
85
- error_message = error_json ['statusInfo' ]
52
+ if 'errors' in error_json :
53
+ if isinstance (error_json ['errors' ], list ):
54
+ err = error_json ['errors' ][0 ]
55
+ error_message = err .get ('message' )
56
+ elif 'error' in error_json :
57
+ error_message = error_json ['error' ]
58
+ elif 'message' in error_json :
59
+ error_message = error_json ['message' ]
86
60
return error_message
87
61
except :
88
62
return response .text or error_message
0 commit comments