Tidying up log, correct HTTP status for error pages.
This commit is contained in:
parent
5285cb2fb5
commit
f8a9197474
|
@ -1,6 +1,5 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import datetime
|
import datetime
|
||||||
import logging
|
|
||||||
import mimetypes
|
import mimetypes
|
||||||
import threading
|
import threading
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
|
@ -33,7 +32,6 @@ app.exception(Exception)(handle_sanic_exception)
|
||||||
@app.before_server_start
|
@app.before_server_start
|
||||||
async def main_start(app, loop):
|
async def main_start(app, loop):
|
||||||
config.load_config()
|
config.load_config()
|
||||||
logger.setLevel(logging.INFO)
|
|
||||||
app.ctx.threadexec = ThreadPoolExecutor(
|
app.ctx.threadexec = ThreadPoolExecutor(
|
||||||
max_workers=8, thread_name_prefix="cista-ioworker"
|
max_workers=8, thread_name_prefix="cista-ioworker"
|
||||||
)
|
)
|
||||||
|
|
|
@ -41,7 +41,9 @@ async def handle_sanic_exception(request, e):
|
||||||
res.cookies.add_cookie("message", message, max_age=5)
|
res.cookies.add_cookie("message", message, max_age=5)
|
||||||
return res
|
return res
|
||||||
# Otherwise use Sanic's default error page
|
# 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):
|
def websocket_wrapper(handler):
|
||||||
|
@ -53,13 +55,14 @@ def websocket_wrapper(handler):
|
||||||
auth.verify(request)
|
auth.verify(request)
|
||||||
await handler(request, ws, *args, **kwargs)
|
await handler(request, ws, *args, **kwargs)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception(e)
|
|
||||||
context, code, message = {}, 500, str(e) or "Internal Server Error"
|
context, code, message = {}, 500, str(e) or "Internal Server Error"
|
||||||
if isinstance(e, SanicException):
|
if isinstance(e, SanicException):
|
||||||
context = e.context or {}
|
context = e.context or {}
|
||||||
code = e.status_code
|
code = e.status_code
|
||||||
message = f"⚠️ {message}" if code < 500 else f"🛑 {message}"
|
message = f"⚠️ {message}" if code < 500 else f"🛑 {message}"
|
||||||
await asend(ws, ErrorMsg({"code": code, "message": message, **context}))
|
await asend(ws, ErrorMsg({"code": code, "message": message, **context}))
|
||||||
|
if not getattr(e, "quiet", False):
|
||||||
|
logger.exception(f"{code} {e!r}")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
Loading…
Reference in New Issue
Block a user