def _handle_session_response(response): """Internal helper for handling API responses from the server. Raises the appropriate exceptions when necessary; otherwise, returns the response. """ if not str(response.status_code).startswith('2'): raise BinanceChainRPCException(response) try: res = response.json() if 'code' in res and res['code'] != "200000": raise BinanceChainRPCException(response) if 'success' in res and not res['success']: raise BinanceChainRPCException(response) # by default return full response # if it's a normal response we have a data attribute, return that if 'result' in res: res = res['result'] return res except ValueError: raise BinanceChainRequestException('Invalid Response: %s' % response.text)
def _handle_response(response): """Internal helper for handling API responses from the server. Raises the appropriate exceptions when necessary; otherwise, returns the response. """ try: res = response.json() if 'error' in res and res['error']: raise BinanceChainRPCException(response) # by default return full response # if it's a normal response we have a data attribute, return that if 'result' in res: res = res['result'] return res except ValueError: raise BinanceChainRequestException('Invalid Response: %s' % response.text)