@@ -143,9 +143,9 @@ def __send_request(self, path, method="GET", params=None, use_token=True, use_js
143
143
headers = {'Authorization' : 'Bearer {}' .format (self .__token )}
144
144
else :
145
145
headers = {}
146
- if use_json_content_type and params :
147
- headers ['Content-Type' ] = 'application/json'
148
- params = json .dumps (params )
146
+ # if use_json_content_type and params:
147
+ headers ['Content-Type' ] = 'application/json'
148
+ params = json .dumps (params )
149
149
150
150
if method == "POST" :
151
151
response = requests .post (url , headers = headers , data = params )
@@ -178,18 +178,16 @@ def __handle_result(self, data):
178
178
"""
179
179
try :
180
180
result = data .json ()
181
+ errors = {}
181
182
except :
182
- result = {
183
+ result = {}
184
+ errors = {
183
185
'is_error' : True ,
184
186
'http_code' : data .status_code ,
185
187
'message' : "Response is empty, invalid or not JSON."
186
188
}
187
189
188
190
if data .ok :
189
- errors = {
190
- 'is_error' : False ,
191
- 'http_code' : data .status_code
192
- }
193
191
logger .debug ("Handle result: {}" .format (result , ))
194
192
else :
195
193
errors = {
@@ -201,11 +199,11 @@ def __handle_result(self, data):
201
199
elif data .status_code == 500 :
202
200
errors [
'message' ]
= "Whoops, looks like something went wrong on the server. Please contact with out support [email protected] ."
203
201
204
- logger .debug ("Handle result: {}" .format (errors , ))
202
+ logger .debug ("Handle result: {}" .format (errors , ))
205
203
206
204
# return object that maintains backward-compatibility
207
- result . update ( errors )
208
- result . update ( {'data' : result . copy ()})
205
+ if not data . ok :
206
+ result = {'data' : errors }
209
207
return result
210
208
211
209
def __handle_error (self , custom_message = None ):
0 commit comments