Make API errors more informative
Fixes https://jira.coreos.com/browse/QUAY-999
This commit is contained in:
parent
beebe6d5ed
commit
4f152fd7c7
2 changed files with 9 additions and 9 deletions
|
@ -32,7 +32,7 @@ def parse_repository_name(include_tag=False,
|
||||||
include_tag=include_tag,
|
include_tag=include_tag,
|
||||||
allow_library=features.LIBRARY_SUPPORT)
|
allow_library=features.LIBRARY_SUPPORT)
|
||||||
except ImplicitLibraryNamespaceNotAllowed:
|
except ImplicitLibraryNamespaceNotAllowed:
|
||||||
abort(400)
|
abort(400, message='A namespace must be specified explicitly')
|
||||||
|
|
||||||
del kwargs[incoming_repo_kwarg]
|
del kwargs[incoming_repo_kwarg]
|
||||||
kwargs[ns_kwarg_name] = repo_name_components[0]
|
kwargs[ns_kwarg_name] = repo_name_components[0]
|
||||||
|
@ -54,7 +54,7 @@ def param_required(param_name, allow_body=False):
|
||||||
def decorated(*args, **kwargs):
|
def decorated(*args, **kwargs):
|
||||||
if param_name not in request.args:
|
if param_name not in request.args:
|
||||||
if not allow_body or param_name not in request.values:
|
if not allow_body or param_name not in request.values:
|
||||||
abort(make_response('Required param: %s' % param_name, 400))
|
abort(400, message='Required param: %s' % param_name)
|
||||||
return wrapped(*args, **kwargs)
|
return wrapped(*args, **kwargs)
|
||||||
return decorated
|
return decorated
|
||||||
return wrapper
|
return wrapper
|
||||||
|
@ -85,7 +85,7 @@ def check_anon_protection(func):
|
||||||
if get_authenticated_context() and not get_authenticated_context().is_anonymous:
|
if get_authenticated_context() and not get_authenticated_context().is_anonymous:
|
||||||
return func(*args, **kwargs)
|
return func(*args, **kwargs)
|
||||||
|
|
||||||
abort(401)
|
abort(401, message='Anonymous access is not allowed')
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
@ -117,7 +117,8 @@ def require_xhr_from_browser(func):
|
||||||
if not has_xhr_header and not app.config.get('DEBUGGING') == True:
|
if not has_xhr_header and not app.config.get('DEBUGGING') == True:
|
||||||
logger.warning('Disallowed possible RTA to URL %s with user agent %s',
|
logger.warning('Disallowed possible RTA to URL %s with user agent %s',
|
||||||
request.path, request.user_agent)
|
request.path, request.user_agent)
|
||||||
abort(400)
|
abort(400, message='API calls must be invoked with an X-Requested-With header ' +
|
||||||
|
'if called from a browser')
|
||||||
|
|
||||||
return func(*args, **kwargs)
|
return func(*args, **kwargs)
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
|
@ -19,7 +19,7 @@ DEFAULT_MESSAGE[409] = 'Conflict'
|
||||||
DEFAULT_MESSAGE[501] = 'Not Implemented'
|
DEFAULT_MESSAGE[501] = 'Not Implemented'
|
||||||
|
|
||||||
|
|
||||||
def _abort(status_code, data_object, headers):
|
def _abort(status_code, data_object, description, headers):
|
||||||
# Add CORS headers to all errors
|
# Add CORS headers to all errors
|
||||||
options_resp = current_app.make_default_options_response()
|
options_resp = current_app.make_default_options_response()
|
||||||
headers['Access-Control-Allow-Origin'] = '*'
|
headers['Access-Control-Allow-Origin'] = '*'
|
||||||
|
@ -31,7 +31,7 @@ def _abort(status_code, data_object, headers):
|
||||||
|
|
||||||
# Report the abort to the user.
|
# Report the abort to the user.
|
||||||
# Raising HTTPException as workaround for https://github.com/pallets/werkzeug/issues/1098
|
# Raising HTTPException as workaround for https://github.com/pallets/werkzeug/issues/1098
|
||||||
new_exception = HTTPException(response=resp)
|
new_exception = HTTPException(response=resp, description=description)
|
||||||
new_exception.code = status_code
|
new_exception.code = status_code
|
||||||
raise new_exception
|
raise new_exception
|
||||||
|
|
||||||
|
@ -42,11 +42,10 @@ def exact_abort(status_code, message=None):
|
||||||
if message is not None:
|
if message is not None:
|
||||||
data['error'] = message
|
data['error'] = message
|
||||||
|
|
||||||
_abort(status_code, data, {})
|
_abort(status_code, data, message or None, {})
|
||||||
|
|
||||||
|
|
||||||
def abort(status_code, message=None, issue=None, headers=None, **kwargs):
|
def abort(status_code, message=None, issue=None, headers=None, **kwargs):
|
||||||
|
|
||||||
message = (str(message) % kwargs if message else
|
message = (str(message) % kwargs if message else
|
||||||
DEFAULT_MESSAGE.get(status_code, ''))
|
DEFAULT_MESSAGE.get(status_code, ''))
|
||||||
|
|
||||||
|
@ -80,4 +79,4 @@ def abort(status_code, message=None, issue=None, headers=None, **kwargs):
|
||||||
if headers is None:
|
if headers is None:
|
||||||
headers = {}
|
headers = {}
|
||||||
|
|
||||||
_abort(status_code, data, headers)
|
_abort(status_code, data, message, headers)
|
||||||
|
|
Reference in a new issue