diff --git a/httpout/response.py b/httpout/response.py index 6edcdb2..381b1e7 100644 --- a/httpout/response.py +++ b/httpout/response.py @@ -42,12 +42,13 @@ async def handle_exception(self, exc): if self.response.request.upgraded: await self.response.handle_exception(exc) else: - if not self.response.headers_sent(): - self.response.set_status(500, b'Internal Server Error') - self.response.set_content_type(b'text/html; charset=utf-8') - self.response.request.http_keepalive = False + self.response.request.http_keepalive = False if isinstance(exc, Exception): + if not self.response.headers_sent(): + self.response.set_status(500, b'Internal Server Error') + self.response.set_content_type(b'text/html; charset=utf-8') + if self.protocol.options['debug']: te = TracebackException.from_exception(exc) await self.response.write(