From 9af22fe1eb9127b39291604b259d7b49a3ceea8c Mon Sep 17 00:00:00 2001 From: Stefan Negru Date: Mon, 26 Jul 2021 08:43:47 +0300 Subject: [PATCH] redirect to bad request on 400, 415 and 422 --- metadata_backend/api/middlewares.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/metadata_backend/api/middlewares.py b/metadata_backend/api/middlewares.py index fbe5fcb70..4545a9912 100644 --- a/metadata_backend/api/middlewares.py +++ b/metadata_backend/api/middlewares.py @@ -47,13 +47,11 @@ async def http_error_handler(req: Request, handler: Callable) -> Response: LOG.error(details) c_type = "application/problem+json" if error.status == 400: - _check_error_page_requested(req, 500) + _check_error_page_requested(req, 400) raise web.HTTPBadRequest(text=details, content_type=c_type) elif error.status == 401: _check_error_page_requested(req, 401) - raise web.HTTPUnauthorized( - headers={"WWW-Authenticate": 'OAuth realm="/", charset="UTF-8"'}, text=details, content_type=c_type - ) + raise web.HTTPUnauthorized(headers={"WWW-Authenticate": 'OAuth realm="/", charset="UTF-8"'}, text=details, content_type=c_type) elif error.status == 403: _check_error_page_requested(req, 403) raise web.HTTPForbidden(text=details, content_type=c_type) @@ -61,10 +59,10 @@ async def http_error_handler(req: Request, handler: Callable) -> Response: _check_error_page_requested(req, 404) raise web.HTTPNotFound(text=details, content_type=c_type) elif error.status == 415: - _check_error_page_requested(req, 500) + _check_error_page_requested(req, 400) raise web.HTTPUnsupportedMediaType(text=details, content_type=c_type) elif error.status == 422: - _check_error_page_requested(req, 500) + _check_error_page_requested(req, 400) raise web.HTTPUnprocessableEntity(text=details, content_type=c_type) else: _check_error_page_requested(req, 500)