From 79afd174c93b25a8ccf6800d1ebff2c05345488a Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Tue, 21 Jan 2020 11:28:08 -0500 Subject: [PATCH] Add serialization to ConfluentExceptions In the same manner that messages are handled, handle non-messages content. --- confluent_server/confluent/exceptions.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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