From a60b0e765d2e96d24636e1e120b5c8b3bf65be42 Mon Sep 17 00:00:00 2001 From: Hussein Mohamed <58296855+whos4n3@users.noreply.github.com> Date: Fri, 5 Nov 2021 15:29:44 +0000 Subject: [PATCH 1/2] Resolves sanic-org /sanic:2297 Added the ability for handle_exception to also dispatch http.lifecyle..response. --- sanic/app.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sanic/app.py b/sanic/app.py index baee112e20..01ac77841d 100644 --- a/sanic/app.py +++ b/sanic/app.py @@ -761,6 +761,14 @@ async def handle_exception( if request.stream: response = request.stream.response if isinstance(response, BaseHTTPResponse): + await self.dispatch( + "http.lifecycle.response", + inline=True, + context={ + "request": request, + "response": response, + }, + ) await response.send(end_stream=True) else: raise ServerError( From 5f53a6e332c0c6534052c9d961c9aacdcea88fd7 Mon Sep 17 00:00:00 2001 From: Adam Hopkins Date: Thu, 18 Nov 2021 12:37:15 +0200 Subject: [PATCH 2/2] Remove extra space --- sanic/app.py | 14 +++++++------- sanic/errorpages.py | 1 - 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/sanic/app.py b/sanic/app.py index c9b75d8718..c785443613 100644 --- a/sanic/app.py +++ b/sanic/app.py @@ -775,13 +775,13 @@ async def handle_exception( if request.stream: response = request.stream.response if isinstance(response, BaseHTTPResponse): - await self.dispatch( - "http.lifecycle.response", - inline=True, - context={ - "request": request, - "response": response, - }, + await self.dispatch( + "http.lifecycle.response", + inline=True, + context={ + "request": request, + "response": response, + }, ) await response.send(end_stream=True) else: diff --git a/sanic/errorpages.py b/sanic/errorpages.py index d046c29d07..4ef59390b6 100644 --- a/sanic/errorpages.py +++ b/sanic/errorpages.py @@ -383,7 +383,6 @@ def exception_response( """ content_type = None - print("exception_response", fallback) if not renderer: # Make sure we have something set renderer = base