From 7fdaf6d1ce44829ccf3e9473353f8df53370e80f Mon Sep 17 00:00:00 2001 From: j Date: Fri, 27 May 2016 11:51:47 +0200 Subject: [PATCH] include Access-Control-Allow-Origin in 404 not found response --- pandora/oxdjango/api/views.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pandora/oxdjango/api/views.py b/pandora/oxdjango/api/views.py index 43591edd..1112a86b 100644 --- a/pandora/oxdjango/api/views.py +++ b/pandora/oxdjango/api/views.py @@ -8,7 +8,7 @@ from django.shortcuts import render_to_response from django.template import RequestContext from django.conf import settings -from ..shortcuts import render_to_json_response, json_response +from ..shortcuts import render_to_json_response, json_response, HttpErrorJson from actions import actions @@ -31,7 +31,9 @@ def api(request): 'settings': settings, 'sitename': settings.SITENAME }) - return render_to_response('api.html', context) + response = render_to_response('api.html', context) + response['Access-Control-Allow-Origin'] = '*' + return response if request.META.get('CONTENT_TYPE') == 'application/json': r = json.loads(request.body) action = r['action'] @@ -45,7 +47,10 @@ def api(request): else: f = actions.get(action) if f: - response = f(request, data) + try: + response = f(request, data) + except HttpErrorJson as e: + response = render_to_json_response(e.response) else: response = render_to_json_response(json_response(status=400, text='Unknown action %s' % action))