return errors when websocket req fails

This commit is contained in:
Victor Shyba 2020-09-02 20:38:30 -03:00
parent 9b15799c72
commit 6bbfb45de7

View file

@ -152,12 +152,19 @@ class Daemon:
else: else:
params = msg.get('params', {}) params = msg.get('params', {})
method = getattr(self.api, msg['method']) method = getattr(self.api, msg['method'])
result = await method(**params) try:
encoded_result = jsonrpc_dumps_pretty(result, service=self.service) result = await method(**params)
await web_socket.send_json({ encoded_result = jsonrpc_dumps_pretty(result, service=self.service)
'id': msg.get('id', ''), await web_socket.send_json({
'result': encoded_result 'id': msg.get('id', ''),
}) 'result': encoded_result
})
except Exception as e:
import traceback
traceback.print_exc()
log.exception("RPC error")
await web_socket.send_json({'id': msg.get('id', ''), 'result': "unexpected error: " + str(e)})
raise e
@staticmethod @staticmethod
async def on_shutdown(app): async def on_shutdown(app):