- result_list = []
- if not isbatch(result):
- result_list.append(result)
- else:
- result_list = result
- for entry in result_list:
- if 'jsonrpc' in entry.keys() and float(entry['jsonrpc']) > 2.0:
- raise NotImplementedError('JSON-RPC version not yet supported.')
- if 'error' in entry.keys() and entry['error'] != None:
- code = entry['error']['code']
- message = entry['error']['message']
- raise ProtocolError('ERROR %s: %s' % (code, message))
- del result_list
+ if not result:
+ # Notification
+ return result
+ if type(result) is not types.DictType:
+ raise TypeError('Response is not a dict.')
+ if 'jsonrpc' in result.keys() and float(result['jsonrpc']) > 2.0:
+ raise NotImplementedError('JSON-RPC version not yet supported.')
+ if 'result' not in result.keys() and 'error' not in result.keys():
+ raise ValueError('Response does not have a result or error key.')
+ if 'error' in result.keys() and result['error'] != None:
+ code = result['error']['code']
+ message = result['error']['message']
+ raise ProtocolError('ERROR %s: %s' % (code, message))