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>
This commit is contained in:
Jan Cholasta
2016-05-18 09:42:56 +02:00
parent 861294c0d6
commit e0275abe6f
10 changed files with 246 additions and 28 deletions

View File

@@ -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:

View File

@@ -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)

View File

@@ -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']