server: fix constructing of HTTP errors
When I added error codes, I missed these exceptions.
This commit is contained in:
parent
0c61e85340
commit
e8c93cd735
|
@ -28,6 +28,7 @@ def _get_user(ctx):
|
||||||
auth_type, credentials = ctx.get_header('Authorization').split(' ', 1)
|
auth_type, credentials = ctx.get_header('Authorization').split(' ', 1)
|
||||||
if auth_type.lower() != 'basic':
|
if auth_type.lower() != 'basic':
|
||||||
raise HttpBadRequest(
|
raise HttpBadRequest(
|
||||||
|
'ValidationError',
|
||||||
'Only basic HTTP authentication is supported.')
|
'Only basic HTTP authentication is supported.')
|
||||||
username, password = base64.decodebytes(
|
username, password = base64.decodebytes(
|
||||||
credentials.encode('ascii')).decode('utf8').split(':')
|
credentials.encode('ascii')).decode('utf8').split(':')
|
||||||
|
|
|
@ -39,7 +39,8 @@ def _create_context(env):
|
||||||
if 'multipart' in env.get('CONTENT_TYPE', ''):
|
if 'multipart' in env.get('CONTENT_TYPE', ''):
|
||||||
form = cgi.FieldStorage(fp=env['wsgi.input'], environ=env)
|
form = cgi.FieldStorage(fp=env['wsgi.input'], environ=env)
|
||||||
if not form.list:
|
if not form.list:
|
||||||
raise errors.HttpBadRequest('No files attached.')
|
raise errors.HttpBadRequest(
|
||||||
|
'ValidationError', 'No files attached.')
|
||||||
body = form.getvalue('metadata')
|
body = form.getvalue('metadata')
|
||||||
for key in form:
|
for key in form:
|
||||||
files[key] = form.getvalue(key)
|
files[key] = form.getvalue(key)
|
||||||
|
@ -55,6 +56,7 @@ def _create_context(env):
|
||||||
params[key] = value
|
params[key] = value
|
||||||
except (ValueError, UnicodeDecodeError):
|
except (ValueError, UnicodeDecodeError):
|
||||||
raise errors.HttpBadRequest(
|
raise errors.HttpBadRequest(
|
||||||
|
'ValidationError',
|
||||||
'Could not decode the request body. The JSON '
|
'Could not decode the request body. The JSON '
|
||||||
'was incorrect or was not encoded as UTF-8.')
|
'was incorrect or was not encoded as UTF-8.')
|
||||||
|
|
||||||
|
@ -67,6 +69,7 @@ def application(env, start_response):
|
||||||
ctx = _create_context(env)
|
ctx = _create_context(env)
|
||||||
if 'application/json' not in ctx.get_header('Accept'):
|
if 'application/json' not in ctx.get_header('Accept'):
|
||||||
raise errors.HttpNotAcceptable(
|
raise errors.HttpNotAcceptable(
|
||||||
|
'ValidationError',
|
||||||
'This API only supports JSON responses.')
|
'This API only supports JSON responses.')
|
||||||
|
|
||||||
for url, allowed_methods in routes.routes.items():
|
for url, allowed_methods in routes.routes.items():
|
||||||
|
@ -75,6 +78,7 @@ def application(env, start_response):
|
||||||
continue
|
continue
|
||||||
if ctx.method not in allowed_methods:
|
if ctx.method not in allowed_methods:
|
||||||
raise errors.HttpMethodNotAllowed(
|
raise errors.HttpMethodNotAllowed(
|
||||||
|
'ValidationError',
|
||||||
'Allowed methods: %r' % allowed_methods)
|
'Allowed methods: %r' % allowed_methods)
|
||||||
|
|
||||||
for hook in middleware.pre_hooks:
|
for hook in middleware.pre_hooks:
|
||||||
|
@ -90,6 +94,7 @@ def application(env, start_response):
|
||||||
return (_dump_json(response).encode('utf-8'),)
|
return (_dump_json(response).encode('utf-8'),)
|
||||||
|
|
||||||
raise errors.HttpNotFound(
|
raise errors.HttpNotFound(
|
||||||
|
'ValidationError',
|
||||||
'Requested path ' + ctx.url + ' was not found.')
|
'Requested path ' + ctx.url + ' was not found.')
|
||||||
|
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
|
|
Loading…
Reference in New Issue