diff --git a/docs/sanic/exceptions.md b/docs/sanic/exceptions.md index cffa219c..d491f23b 100644 --- a/docs/sanic/exceptions.md +++ b/docs/sanic/exceptions.md @@ -43,3 +43,11 @@ Some of the most useful exceptions are presented below: usually occurs if there is an exception raised in user code. See the `sanic.exceptions` module for the full list of exceptions to throw. + +You can also use `exceptions_base`, it can catch the exception just like +normal catching. It can be used for catching all unexpected error and eliminate +the risk that server information being stolen by attackers/ + +@app.exception_base(Exception) +def catch_everything(request, exception): + return text( "Server Error!",500) diff --git a/sanic/handlers.py b/sanic/handlers.py index 31e21c9a..a57f7249 100644 --- a/sanic/handlers.py +++ b/sanic/handlers.py @@ -18,6 +18,7 @@ from sanic.response import text, html class ErrorHandler: handlers = None + handlers_base = None cached_handlers = None _missing = object()