Temporary fix for additional exception classes handled in Flask
The recent change to Flask-restful broke the other registered exception handlers, so this temporarily handles the decorated cases as well, until we put in place a proper registration model for Flask and Flask-restful handled exceptions
This commit is contained in:
parent
a0c82d03a0
commit
b465a34e8f
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,
|
||||
FreshLoginRequired, NotFound)
|
||||
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.names import parse_namespace_repository
|
||||
from util.pagination import encrypt_page_token, decrypt_page_token
|
||||
from util.useremails import CannotSendEmailException
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
api_bp = Blueprint('api', __name__)
|
||||
|
@ -35,6 +39,20 @@ api_bp = Blueprint('api', __name__)
|
|||
class ApiExceptionHandlingApi(Api):
|
||||
@crossdomain(origin='*', headers=['Authorization', 'Content-Type'])
|
||||
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):
|
||||
response = Response(json.dumps(error.to_dict()), error.status_code,
|
||||
mimetype='application/json')
|
||||
|
|
Reference in a new issue