Skip to content

Commit 20eee27

Browse files
committed
Log error and check if maformed first
1 parent a66aff1 commit 20eee27

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

test/functional/test_framework/authproxy.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,21 @@ def get_request(self, *args, **argsn):
137137
def __call__(self, *args, **argsn):
138138
postdata = json.dumps(self.get_request(*args, **argsn), default=EncodeDecimal, ensure_ascii=self.ensure_ascii)
139139
response, status = self._request('POST', self.__url.path, postdata.encode('utf-8'))
140-
if response['error'] is not None:
141-
raise JSONRPCException(response['error'])
140+
log.debug("Raw response content: %s", response)
141+
if not isinstance(response, dict):
142+
raise JSONRPCException({
143+
'code': -342,
144+
'message': 'Received non-JSON or malformed JSON response'
145+
})
146+
147+
if response.get('error') is not None:
148+
raise JSONRPCException(response['error'], status)
142149
elif 'result' not in response:
143150
raise JSONRPCException({
144-
'code': -343, 'message': 'missing JSON-RPC result'})
151+
'code': -343, 'message': 'missing JSON-RPC result'}, status)
152+
elif status != HTTPStatus.OK:
153+
raise JSONRPCException({
154+
'code': -342, 'message': 'non-200 HTTP status code but no JSON-RPC error'}, status)
145155
else:
146156
assert response['jsonrpc'] == '2.0'
147157
if status != HTTPStatus.OK:

0 commit comments

Comments
 (0)