Skip to content

Commit

Permalink
redirect to bad request on 400, 415 and 422
Browse files Browse the repository at this point in the history
  • Loading branch information
blankdots committed Jul 26, 2021
1 parent b85b2fc commit 9af22fe
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions metadata_backend/api/middlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,22 @@ 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)
elif error.status == 404:
_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)
Expand Down

0 comments on commit 9af22fe

Please sign in to comment.