pylightning: add method and payload as proper fields.

They're much more useful being programatically-accessible, AFAICT.

The string stays the same so they're backwards compatible.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2018-08-08 11:29:48 +09:30 committed by Christian Decker
parent d8a6028214
commit 60b95d4764
2 changed files with 8 additions and 8 deletions

View file

@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Protocol: gossipd now deliberately delays spamming with `channel_update`. - Protocol: gossipd now deliberately delays spamming with `channel_update`.
- Config: `--conf` option to set config file. - Config: `--conf` option to set config file.
- JSON API: Added description to invoices and payments (#1740). - JSON API: Added description to invoices and payments (#1740).
- pylightning: RpcError now has `method` and `payload` fields.
### Changed ### Changed

View file

@ -4,8 +4,12 @@ import socket
class RpcError(ValueError): class RpcError(ValueError):
def __init__(self, description, error=None): def __init__(self, method, payload, error):
super(ValueError, self).__init__(description) super(ValueError, self).__init__("RPC call failed: method: {}, payload: {}, error: {}"
.format(method, payload, error))
self.method = method
self.payload = payload
self.error = error self.error = error
@ -73,12 +77,7 @@ class UnixDomainSocketRpc(object):
self.logger.debug("Received response for %s call: %r", method, resp) self.logger.debug("Received response for %s call: %r", method, resp)
if "error" in resp: if "error" in resp:
raise RpcError( raise RpcError(method, payload, resp['error'])
"RPC call failed: method: {}, payload: {}, error: {}".format(
method,
payload,
resp['error']
), resp['error'])
elif "result" not in resp: elif "result" not in resp:
raise ValueError("Malformed response, \"result\" missing.") raise ValueError("Malformed response, \"result\" missing.")
return resp["result"] return resp["result"]