Add CORS headers to all error responses.
This commit is contained in:
parent
669ec9c382
commit
5d2274fb05
1 changed files with 11 additions and 1 deletions
12
util/http.py
12
util/http.py
|
@ -2,7 +2,7 @@ import logging
|
|||
import json
|
||||
|
||||
from app import mixpanel
|
||||
from flask import request, abort as flask_abort, make_response
|
||||
from flask import request, abort as flask_abort, make_response, current_app
|
||||
from auth.auth_context import get_authenticated_user, get_validated_token
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -54,6 +54,16 @@ def abort(status_code, message=None, issue=None, headers=None, **kwargs):
|
|||
if issue_url:
|
||||
data['info_url'] = issue_url
|
||||
|
||||
if headers is None:
|
||||
headers = {}
|
||||
|
||||
# Add CORS headers to all errors
|
||||
options_resp = current_app.make_default_options_response()
|
||||
headers['Access-Control-Allow-Origin'] = '*'
|
||||
headers['Access-Control-Allow-Methods'] = options_resp.headers['allow']
|
||||
headers['Access-Control-Max-Age'] = str(21600)
|
||||
headers['Access-Control-Allow-Headers'] = ['Authorization', 'Content-Type']
|
||||
|
||||
resp = make_response(json.dumps(data), status_code, headers)
|
||||
|
||||
# Report the abort to the user.
|
||||
|
|
Reference in a new issue