Skip to content

Add access to error.data #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jsonrpclib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
from jsonrpclib.history import History
history = History.instance()
from jsonrpclib.jsonrpc import Server, MultiCall, Fault
from jsonrpclib.jsonrpc import ProtocolError, loads, dumps
from jsonrpclib.jsonrpc import ProtocolError, AppError, loads, dumps
9 changes: 8 additions & 1 deletion jsonrpclib/jsonrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ def jloads(json_string):

class ProtocolError(Exception):
pass
class AppError(ProtocolError):
def data(self):
return self[0][2]

class TransportMixIn(object):
""" Just extends the XMLRPC transport where necessary. """
Expand Down Expand Up @@ -526,7 +529,11 @@ def check_for_errors(result):
if 'error' in result.keys() and result['error'] != None:
code = result['error']['code']
message = result['error']['message']
raise ProtocolError((code, message))
if -32700 <= code <= -32000:
# pre-defined errors, see http://www.jsonrpc.org/specification#error_object
raise ProtocolError((code, message))
else:
raise AppError((code, message, result['error'].get('data', None)))
return result

def isbatch(result):
Expand Down