2
0
mirror of https://github.com/xcat2/confluent.git synced 2024-11-25 19:10:10 +00:00

Provide means of asynchttp of passing exceptions

This allows client code to be actually same when
using synchronous versus asynchonous.
This commit is contained in:
Jarrod Johnson 2016-09-28 15:00:49 -04:00
parent fbd5059ade
commit d4ffc41451
2 changed files with 11 additions and 3 deletions

View File

@ -110,9 +110,12 @@ class AsyncSession(object):
del _asyncsessions[self.asyncid]
def run_handler(self, handler, requestid):
for rsp in handler:
self.add(requestid, rsp)
self.add(requestid, messages.AsyncCompletion())
try:
for rsp in handler:
self.add(requestid, rsp)
self.add(requestid, messages.AsyncCompletion())
except Exception as e:
self.add(requestid, e)
def get_responses(self, timeout=25):
self.reaper.cancel()

View File

@ -880,6 +880,11 @@ class AsyncMessage(ConfluentMessage):
if (isinstance(rsp, ConfluentMessage) or
isinstance(rsp, ConfluentNodeError)):
rspdict = rsp.raw()
elif isinstance(rsp, exc.ConfluentException):
rspdict = {'exceptioncode': rsp.apierrorcode,
'exception': rsp.get_error_body()}
elif isinstance(rsp, Exception):
rspdict = {'exceptioncode': 500, 'exception': str(rsp)}
elif isinstance(rsp, dict): # console metadata
rspdict = rsp
else: # terminal text