Send no ID for batch request errors

Fixes #54
This commit is contained in:
Neil Booth 2016-12-03 10:56:55 +09:00
parent 2edb762b83
commit 625508f5c6

View File

@ -211,16 +211,17 @@ class JSONRPC(asyncio.Protocol, LoggedClass):
if self.transport.is_closing():
return
id_ = payload.get('id') if isinstance(payload, dict) else None
try:
data = (json.dumps(payload) + '\n').encode()
except TypeError:
msg = 'JSON encoding failure: {}'.format(payload)
self.logger.error(msg)
self.send_json_error(msg, self.INTERNAL_ERROR, payload.get('id'))
self.send_json_error(msg, self.INTERNAL_ERROR, id_)
else:
if len(data) > max(1000, self.max_send):
self.send_json_error('request too large', self.INVALID_REQUEST,
payload.get('id'))
self.send_json_error('request too large',
self.INVALID_REQUEST, id_)
raise self.LargeRequestError
else:
self.send_count += 1