Merge pull request #2535 from coreos-inc/api-error-tempfix
Temporary fix for additional exception classes handled in Flask
This commit is contained in:
commit
2363737055
1 changed files with 18 additions and 0 deletions
|
@ -24,9 +24,13 @@ from endpoints.csrf import csrf_protect
|
||||||
from endpoints.exception import (ApiException, Unauthorized, InvalidRequest, InvalidResponse,
|
from endpoints.exception import (ApiException, Unauthorized, InvalidRequest, InvalidResponse,
|
||||||
FreshLoginRequired, NotFound)
|
FreshLoginRequired, NotFound)
|
||||||
from endpoints.decorators import check_anon_protection
|
from endpoints.decorators import check_anon_protection
|
||||||
|
from endpoints.decorated import (handle_dme, handle_emailexception, handle_configexception,
|
||||||
|
handle_too_many_login_attempts)
|
||||||
|
from util.config.provider.baseprovider import CannotWriteConfigException
|
||||||
from util.metrics.metricqueue import time_decorator
|
from util.metrics.metricqueue import time_decorator
|
||||||
from util.names import parse_namespace_repository
|
from util.names import parse_namespace_repository
|
||||||
from util.pagination import encrypt_page_token, decrypt_page_token
|
from util.pagination import encrypt_page_token, decrypt_page_token
|
||||||
|
from util.useremails import CannotSendEmailException
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
api_bp = Blueprint('api', __name__)
|
api_bp = Blueprint('api', __name__)
|
||||||
|
@ -35,6 +39,20 @@ api_bp = Blueprint('api', __name__)
|
||||||
class ApiExceptionHandlingApi(Api):
|
class ApiExceptionHandlingApi(Api):
|
||||||
@crossdomain(origin='*', headers=['Authorization', 'Content-Type'])
|
@crossdomain(origin='*', headers=['Authorization', 'Content-Type'])
|
||||||
def handle_error(self, error):
|
def handle_error(self, error):
|
||||||
|
# TODO: Fix this into a proper error registration model that works in *both* Flask and
|
||||||
|
# Flask-Restful!
|
||||||
|
if isinstance(error, model.DataModelException):
|
||||||
|
return handle_dme(error)
|
||||||
|
|
||||||
|
if isinstance(error, CannotSendEmailException):
|
||||||
|
return handle_emailexception(error)
|
||||||
|
|
||||||
|
if isinstance(error, CannotWriteConfigException):
|
||||||
|
return handle_configexception(error)
|
||||||
|
|
||||||
|
if isinstance(error, model.TooManyLoginAttemptsException):
|
||||||
|
return handle_too_many_login_attempts(error)
|
||||||
|
|
||||||
if isinstance(error, ApiException):
|
if isinstance(error, ApiException):
|
||||||
response = Response(json.dumps(error.to_dict()), error.status_code,
|
response = Response(json.dumps(error.to_dict()), error.status_code,
|
||||||
mimetype='application/json')
|
mimetype='application/json')
|
||||||
|
|
Reference in a new issue