From a24d96b098a6584d547120edac6c6ee1f7444449 Mon Sep 17 00:00:00 2001 From: j Date: Thu, 7 Nov 2024 14:28:28 +0000 Subject: [PATCH] log invalid api requests --- pandora/oxdjango/api/views.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pandora/oxdjango/api/views.py b/pandora/oxdjango/api/views.py index 3a4a2e89..ce7df892 100644 --- a/pandora/oxdjango/api/views.py +++ b/pandora/oxdjango/api/views.py @@ -34,8 +34,15 @@ def api(request): return response if request.META.get('CONTENT_TYPE') == 'application/json': r = json.loads(request.body.decode('utf-8')) - action = r['action'] - data = r.get('data', {}) + if 'action' not in r: + 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: action = request.POST['action'] data = json.loads(request.POST.get('data', '{}'))