traces for value and assertion errors

This commit is contained in:
dni ⚡
2024-10-17 10:42:29 +02:00
parent 3a1064c841
commit 33bc380594
+4
View File
@@ -70,6 +70,8 @@ def register_exception_handlers(app: FastAPI):
@app.exception_handler(AssertionError)
async def assert_error_handler(request: Request, exc: AssertionError):
etype, _, tb = sys.exc_info()
traceback.print_exception(etype, exc, tb)
logger.warning(f"AssertionError: {exc!s}")
return render_html_error(request, exc) or JSONResponse(
status_code=HTTPStatus.BAD_REQUEST,
@@ -78,6 +80,8 @@ def register_exception_handlers(app: FastAPI):
@app.exception_handler(ValueError)
async def value_error_handler(request: Request, exc: ValueError):
etype, _, tb = sys.exc_info()
traceback.print_exception(etype, exc, tb)
logger.warning(f"ValueError: {exc!s}")
return render_html_error(request, exc) or JSONResponse(
status_code=HTTPStatus.BAD_REQUEST,