Fix bug where ws exceptions not being logged (#2213)
* Fix bug where ws exceptions not being logged * Fix t\est
This commit is contained in:
@@ -893,6 +893,8 @@ class Sanic(BaseSanic, metaclass=TouchUpMeta):
|
||||
self.websocket_tasks.add(fut)
|
||||
try:
|
||||
await fut
|
||||
except Exception as e:
|
||||
self.error_handler.log(request, e)
|
||||
except (CancelledError, ConnectionClosed):
|
||||
pass
|
||||
finally:
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
from traceback import format_exc
|
||||
|
||||
from sanic.errorpages import exception_response
|
||||
from sanic.exceptions import (
|
||||
ContentRangeError,
|
||||
@@ -99,7 +97,6 @@ class ErrorHandler:
|
||||
if response is None:
|
||||
response = self.default(request, exception)
|
||||
except Exception:
|
||||
self.log(format_exc())
|
||||
try:
|
||||
url = repr(request.url)
|
||||
except AttributeError:
|
||||
@@ -115,11 +112,6 @@ class ErrorHandler:
|
||||
return text("An error occurred while handling an error", 500)
|
||||
return response
|
||||
|
||||
def log(self, message, level="error"):
|
||||
"""
|
||||
Deprecated, do not use.
|
||||
"""
|
||||
|
||||
def default(self, request, exception):
|
||||
"""
|
||||
Provide a default behavior for the objects of :class:`ErrorHandler`.
|
||||
@@ -135,6 +127,11 @@ class ErrorHandler:
|
||||
:class:`Exception`
|
||||
:return:
|
||||
"""
|
||||
self.log(request, exception)
|
||||
return exception_response(request, exception, self.debug)
|
||||
|
||||
@staticmethod
|
||||
def log(request, exception):
|
||||
quiet = getattr(exception, "quiet", False)
|
||||
if quiet is False:
|
||||
try:
|
||||
@@ -142,13 +139,10 @@ class ErrorHandler:
|
||||
except AttributeError:
|
||||
url = "unknown"
|
||||
|
||||
self.log(format_exc())
|
||||
error_logger.exception(
|
||||
"Exception occurred while handling uri: %s", url
|
||||
)
|
||||
|
||||
return exception_response(request, exception, self.debug)
|
||||
|
||||
|
||||
class ContentRangeHandler:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user