Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def handle_rpc():
json_body = {}
try:
if bottle.request.headers['CONTENT_TYPE'] \
not in ('application/json', 'application/json-rpc'):
raise ParseError(
message='Invalid content type.',
data=bottle.request.headers['CONTENT_TYPE'])
try:
json_body = bottle.json_loads(
bottle.request.body.read())
except ValueError:
raise ParseError(
message='Invalid JSON.',
data=json.dumps(traceback.format_exc()))
response = self._endpoint.rpc(json_body)
# If we have error set the HTTP status code
if 'error' in response:
error = response['error']
status = jsonrpc_code_to_status.get(error['code'], 500)
bottle.response.status = status
def __init__(self, message='Parse error.', data=None):
super(ParseError, self).__init__(PARSE_ERROR, message, data)