From 14c153720f5e50232cf75b4c2c5da273b3f16e85 Mon Sep 17 00:00:00 2001 From: Konstantina Chremmou Date: Tue, 12 Dec 2017 14:43:34 +0000 Subject: [PATCH] Spec incompliance: the truth of the error object should not depend on the code being non 0. According to the JSON_RPC v2.0 specs (http://www.jsonrpc.org/specification), the error response should contain an 'error' object which has at least 'code' and 'message' objects, hence the truth of the error object should depend on their existence. Although not an optimum selection, 0 is not disallowed as error code. Signed-off-by: Konstantina Chremmou --- pyjsonrpc/rpcerror.py | 2 +- pyjsonrpc/rpcresponse.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pyjsonrpc/rpcerror.py b/pyjsonrpc/rpcerror.py index fe224c8..9f2e608 100644 --- a/pyjsonrpc/rpcerror.py +++ b/pyjsonrpc/rpcerror.py @@ -31,7 +31,7 @@ def __init__(self, message = None, data = None, code = None): self.message = message or self.message self.data = data self.code = code or self.code - assert self.code, "Error without code is not allowed." + assert self.code is not None, "Error without code is not allowed." def __str__(self): return "JsonRpcError({code}): {message}".format( diff --git a/pyjsonrpc/rpcresponse.py b/pyjsonrpc/rpcresponse.py index fdfc5f5..f0a34e9 100644 --- a/pyjsonrpc/rpcresponse.py +++ b/pyjsonrpc/rpcresponse.py @@ -20,7 +20,7 @@ def __init__(self, code, message, data): """ :param code: Error code :param message: Error message - :param data: Additional error informations + :param data: Additional error information """ Bunch.__init__(self) @@ -29,7 +29,7 @@ def __init__(self, code, message, data): self.data = data def __len__(self): - return 1 if self.code else 0 + return 0 if (self.code is None) or (self.message is None) else 1 def __init__(