Skip to content
This repository has been archived by the owner on Mar 1, 2018. It is now read-only.

Commit

Permalink
Warn on error handlers returning a different code to their exception.
Browse files Browse the repository at this point in the history
Signed-off-by: Laura <l@veriny.tf>
  • Loading branch information
Fuyukai committed Jul 25, 2017
1 parent f0872b4 commit c3e3c32
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions kyoukai/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ async def handle_httpexception(self, ctx: HTTPRequestContext, exception: HTTPExc
# else:
# result = wrap_response(result, self.response_class)

if result.status_code != exception.code:
logger.warning("Error handler {} returned code {} when exception was code {}..."
.format(error_handler.callable_repr, result.status_code,
exception.code))

return result

async def process_request(self, request: Request, parent_context: Context) -> Response:
Expand Down
4 changes: 4 additions & 0 deletions kyoukai/route.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ def __init__(self, function, *,
#: Our own specific hooks.
self.hooks = {}

@property
def callable_repr(self):
return repr(self._callable)

def add_path(self, url: str, methods: typing.Sequence[str] = ("GET", "HEAD")):
"""
Adds a path to the current set of paths for this route.
Expand Down

0 comments on commit c3e3c32

Please sign in to comment.