log invalid api requests

This commit is contained in:
j 2024-11-07 14:28:28 +00:00
parent 03daede441
commit a24d96b098

View file

@ -34,8 +34,15 @@ def api(request):
return response return response
if request.META.get('CONTENT_TYPE') == 'application/json': if request.META.get('CONTENT_TYPE') == 'application/json':
r = json.loads(request.body.decode('utf-8')) r = json.loads(request.body.decode('utf-8'))
action = r['action'] if 'action' not in r:
data = r.get('data', {}) logger.error("invalid api request: %s", r)
response = render_to_json_response(json_response(status=400,
text='Invalid request'))
response['Access-Control-Allow-Origin'] = '*'
return response
else:
action = r['action']
data = r.get('data', {})
else: else:
action = request.POST['action'] action = request.POST['action']
data = json.loads(request.POST.get('data', '{}')) data = json.loads(request.POST.get('data', '{}'))