diff options
author | Jan Cholasta <jcholast@redhat.com> | 2016-05-18 09:42:56 +0200 |
---|---|---|
committer | Jan Cholasta <jcholast@redhat.com> | 2016-05-25 16:06:26 +0200 |
commit | e0275abe6f5192e68b7f57acf37b01aaa89003ea (patch) | |
tree | 3023bbb3db7e3369e865eabfe6b878e09cf7d38c /ipalib | |
parent | 861294c0d62891dc9977e7203cc07496e35ec939 (diff) | |
download | freeipa-e0275abe6f5192e68b7f57acf37b01aaa89003ea.tar.gz freeipa-e0275abe6f5192e68b7f57acf37b01aaa89003ea.tar.xz freeipa-e0275abe6f5192e68b7f57acf37b01aaa89003ea.zip |
rpc: include structured error information in responses
Include keyword arguments of exceptions in RPC responses. This is limited
to JSON-RPC, as XML-RPC does not support additional data in error
responses.
Include keyword arguments of messages in RPC responses.
Include keyword arguments of exceptions in batch command result.
https://fedorahosted.org/freeipa/ticket/4739
Reviewed-By: David Kupka <dkupka@redhat.com>
Diffstat (limited to 'ipalib')
-rw-r--r-- | ipalib/messages.py | 7 | ||||
-rw-r--r-- | ipalib/plugins/batch.py | 1 | ||||
-rw-r--r-- | ipalib/rpc.py | 4 |
3 files changed, 11 insertions, 1 deletions
diff --git a/ipalib/messages.py b/ipalib/messages.py index c37cceb3f..c760e9d37 100644 --- a/ipalib/messages.py +++ b/ipalib/messages.py @@ -49,6 +49,12 @@ def add_message(version, result, message): def process_message_arguments(obj, format=None, message=None, **kw): + for key, value in kw.items(): + if not isinstance(value, six.integer_types): + try: + kw[key] = unicode(value) + except UnicodeError: + pass obj.kw = kw name = obj.__class__.__name__ if obj.format is not None and format is not None: @@ -120,6 +126,7 @@ class PublicMessage(UserWarning): name=unicode(type(self).__name__), message=self.strerror, code=self.errno, + data=self.kw, ) if six.PY3: diff --git a/ipalib/plugins/batch.py b/ipalib/plugins/batch.py index 42edba2ad..6a5b383ff 100644 --- a/ipalib/plugins/batch.py +++ b/ipalib/plugins/batch.py @@ -136,6 +136,7 @@ class batch(Command): error=reported_error.strerror, error_code=reported_error.errno, error_name=unicode(type(reported_error).__name__), + error_kw=reported_error.kw, ) results.append(result) return dict(count=len(results) , results=results) diff --git a/ipalib/rpc.py b/ipalib/rpc.py index 55b8abb8d..16db33168 100644 --- a/ipalib/rpc.py +++ b/ipalib/rpc.py @@ -1097,7 +1097,9 @@ class JSONServerProxy(object): server=self.__host, ) else: - raise error_class(message=error['message']) + kw = error.get('data', {}) + kw['message'] = error['message'] + raise error_class(**kw) return response['result'] |