aboutsummaryrefslogtreecommitdiff
path: root/server/szurubooru/rest
diff options
context:
space:
mode:
authorrr-2016-09-26 22:51:07 +0200
committerrr-2016-09-26 22:51:07 +0200
commite8c93cd73595b323a1ae4da4b43694fdc73ba73d (patch)
tree41ba2b2b444d72bc2d7eac39a14e4e77bdf0b9b7 /server/szurubooru/rest
parent0c61e853404374ad59ca3e252bad125232096eff (diff)
server: fix constructing of HTTP errors
When I added error codes, I missed these exceptions.
Diffstat (limited to 'server/szurubooru/rest')
-rw-r--r--server/szurubooru/rest/app.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/server/szurubooru/rest/app.py b/server/szurubooru/rest/app.py
index 2c2b70b..3cb5317 100644
--- a/server/szurubooru/rest/app.py
+++ b/server/szurubooru/rest/app.py
@@ -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:

© 2015 - 2026 Jakob L. Kreuze