Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions channels_jsonrpc/jsonrpcconsumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ def error(_id, code, message, data=None):
def notify_channel(self, method, params):
"""
Notify a group. Using JSON-RPC notificatons
:param reply_channel: Reply channel
:param method: JSON-RPC method
:param params: parmas of the method
:return:
Expand Down Expand Up @@ -328,10 +327,30 @@ def _base_receive_json(self, content):

# Send response back only if it is a call, not notification
if not is_notification:
self.send_json(result)
try:
self.send_json(result)
except Exception as e:
# The only thing we know can fail here is sending to a closed
# socket, so just log it. Sadly at this point we have
# to except so broadly because actual exception type depends
# on what ASGI server we're running on.
logger.warning(
"Could not send JSON response back to user on socket: %s",
e,
)


class AsyncRpcBase(RpcBase):
async def notify_channel(self, method, params):
"""
Notify a group. Using JSON-RPC notificatons
:param method: JSON-RPC method
:param params: parmas of the method
:return:
"""
content = self.json_rpc_frame(method=method, params=params)
await self.send(await self.encode_json(content))

async def __get_result(self, method, params):

func_args = getattr(getfullargspec(method), keywords_args)
Expand Down Expand Up @@ -424,7 +443,17 @@ async def _base_receive_json(self, content):

# Send response back only if it is a call, not notification
if not is_notification:
await self.send_json(result)
try:
await self.send_json(result)
except Exception as e:
# The only thing we know can fail here is sending to a closed
# socket, so just log it. Sadly at this point we have
# to except so broadly because actual exception type depends
# on what ASGI server we're running on.
logger.warning(
"Could not send JSON response back to user on socket: %s",
e,
)


class JsonRpcWebsocketConsumer(JsonWebsocketConsumer, RpcBase):
Expand Down