server: fix constructing of HTTP errors

When I added error codes, I missed these exceptions.
This commit is contained in:
rr- 2016-09-26 22:51:07 +02:00
parent 0c61e85340
commit e8c93cd735
2 changed files with 7 additions and 1 deletions

View File

@ -28,6 +28,7 @@ def _get_user(ctx):
auth_type, credentials = ctx.get_header('Authorization').split(' ', 1)
if auth_type.lower() != 'basic':
raise HttpBadRequest(
'ValidationError',
'Only basic HTTP authentication is supported.')
username, password = base64.decodebytes(
credentials.encode('ascii')).decode('utf8').split(':')

View File

@ -39,7 +39,8 @@ def _create_context(env):
if 'multipart' in env.get('CONTENT_TYPE', ''):
form = cgi.FieldStorage(fp=env['wsgi.input'], environ=env)
if not form.list:
raise errors.HttpBadRequest('No files attached.')
raise errors.HttpBadRequest(
'ValidationError', 'No files attached.')
body = form.getvalue('metadata')
for key in form:
files[key] = form.getvalue(key)
@ -55,6 +56,7 @@ def _create_context(env):
params[key] = value
except (ValueError, UnicodeDecodeError):
raise errors.HttpBadRequest(
'ValidationError',
'Could not decode the request body. The JSON '
'was incorrect or was not encoded as UTF-8.')
@ -67,6 +69,7 @@ def application(env, start_response):
ctx = _create_context(env)
if 'application/json' not in ctx.get_header('Accept'):
raise errors.HttpNotAcceptable(
'ValidationError',
'This API only supports JSON responses.')
for url, allowed_methods in routes.routes.items():
@ -75,6 +78,7 @@ def application(env, start_response):
continue
if ctx.method not in allowed_methods:
raise errors.HttpMethodNotAllowed(
'ValidationError',
'Allowed methods: %r' % allowed_methods)
for hook in middleware.pre_hooks:
@ -90,6 +94,7 @@ def application(env, start_response):
return (_dump_json(response).encode('utf-8'),)
raise errors.HttpNotFound(
'ValidationError',
'Requested path ' + ctx.url + ' was not found.')
except Exception as ex: