diff --git a/cista/app.py b/cista/app.py index 4d4e1bb..c36a858 100644 --- a/cista/app.py +++ b/cista/app.py @@ -1,6 +1,5 @@ import asyncio import datetime -import logging import mimetypes import threading from concurrent.futures import ThreadPoolExecutor @@ -33,7 +32,6 @@ app.exception(Exception)(handle_sanic_exception) @app.before_server_start async def main_start(app, loop): config.load_config() - logger.setLevel(logging.INFO) app.ctx.threadexec = ThreadPoolExecutor( max_workers=8, thread_name_prefix="cista-ioworker" ) diff --git a/cista/util/apphelpers.py b/cista/util/apphelpers.py index c0433b1..786c7f1 100644 --- a/cista/util/apphelpers.py +++ b/cista/util/apphelpers.py @@ -41,7 +41,9 @@ async def handle_sanic_exception(request, e): res.cookies.add_cookie("message", message, max_age=5) return res # Otherwise use Sanic's default error page - return errorpages.HTMLRenderer(request, e, debug=request.app.debug).full() + res = errorpages.HTMLRenderer(request, e, debug=request.app.debug).full() + res.status = status # Unfortunately Sanic <23.12 doesn't set this + return res def websocket_wrapper(handler): @@ -53,13 +55,14 @@ def websocket_wrapper(handler): auth.verify(request) await handler(request, ws, *args, **kwargs) except Exception as e: - logger.exception(e) context, code, message = {}, 500, str(e) or "Internal Server Error" if isinstance(e, SanicException): context = e.context or {} code = e.status_code message = f"⚠️ {message}" if code < 500 else f"🛑 {message}" await asend(ws, ErrorMsg({"code": code, "message": message, **context})) + if not getattr(e, "quiet", False): + logger.exception(f"{code} {e!r}") raise return wrapper