diff --git a/confluent_server/confluent/exceptions.py b/confluent_server/confluent/exceptions.py index d9a7f5ab..619d24b5 100644 --- a/confluent_server/confluent/exceptions.py +++ b/confluent_server/confluent/exceptions.py @@ -17,7 +17,15 @@ import base64 import json +import msgpack +def deserilaize_exc(msg): + excd = msgpack.unpackb(msg) + if excd[0] not in globals(): + return False + if not issubclass(excd[0], ConfluentException): + return False + return globals(excd[0])(*excd[1]) class ConfluentException(Exception): apierrorcode = 500 @@ -27,6 +35,9 @@ class ConfluentException(Exception): errstr = ' - '.join((self._apierrorstr, str(self))) return json.dumps({'error': errstr }) + def serialize(self): + return msgpack.packb([self.__class__.__name__, [str(self)]]) + @property def apierrorstr(self): if str(self): @@ -104,6 +115,7 @@ class PubkeyInvalid(ConfluentException): def __init__(self, text, certificate, fingerprint, attribname, event): super(PubkeyInvalid, self).__init__(self, text) + self.myargs = (text, certificate, fingerprint, attribname, event) self.fingerprint = fingerprint self.attrname = attribname self.message = text @@ -117,6 +129,9 @@ class PubkeyInvalid(ConfluentException): 'certificate': certtxt} self.errorbody = json.dumps(bodydata) + def serialize(self): + return msgpack.packb([self.__class__.__name__, self.myargs]) + def get_error_body(self): return self.errorbody