Skip to content

Commit

Permalink
Added error event
Browse files Browse the repository at this point in the history
Added on_winerp_error event
Fixed JSON serializable error when a non-serializable object is passed on response
  • Loading branch information
nouman0103 authored Apr 9, 2022
1 parent d4a9fae commit 44f4148
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions client.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def __init__(self, local_name, loop = None, port=13254):
"on_winerp_request": None,
"on_winerp_response": None,
"on_winerp_information": None,
"on_winerp_error": None
}

async def __empty_event(self, *args, **kwargs):
Expand Down Expand Up @@ -215,6 +216,7 @@ async def __on_message(self):
logger.warn("Another client is already connected. Requests will be enabled when the other is disconnected.")
else:
logger.debug("Failed to fulfill request: %s" % message.data)
self.loop.create_task(self.get_event("on_winerp_error")(message.data))

if message.uuid is not None:
self.loop.create_task(self._dispatch(message))
Expand All @@ -237,8 +239,10 @@ async def _fulfill_request(self, message: WsMessage):

try:
payload.data = await func(**data)
json.dumps(payload.data) #Ensuring data is serializable
except Exception as error:
logger.exception(error)
self.loop.create_task(self.get_event("on_winerp_error")(error))
etype = type(error)
trace = error.__traceback__
lines = traceback.format_exception(etype, error, trace)
Expand Down

0 comments on commit 44f4148

Please sign in to comment.