api: fixed potential crash when returning error response using JSON objects that fail to parse.

This commit is contained in:
Marcin Kuzminski 2018-12-18 11:42:52 +01:00
parent 47db530369
commit 1e446c9382

View file

@ -142,13 +142,13 @@ def exception_view(exc, request):
fault_message = 'undefined error'
if isinstance(exc, JSONRPCError):
fault_message = exc.message
fault_message = safe_str(exc.message)
log.debug('json-rpc error rpc_id:%s "%s"', rpc_id, fault_message)
elif isinstance(exc, JSONRPCValidationError):
colander_exc = exc.colander_exception
# TODO(marcink): think maybe of nicer way to serialize errors ?
fault_message = colander_exc.asdict()
log.debug('json-rpc error rpc_id:%s "%s"', rpc_id, fault_message)
log.debug('json-rpc colander error rpc_id:%s "%s"', rpc_id, fault_message)
elif isinstance(exc, JSONRPCForbidden):
fault_message = 'Access was denied to this resource.'
log.warning('json-rpc forbidden call rpc_id:%s "%s"', rpc_id, fault_message)