From 4071925f654233ec2d15176f4c944e6b766a54fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Tue, 27 May 2025 11:37:38 +0200 Subject: [PATCH] feat: mask unexcepted error and add a exception id (#3178) --- lnbits/exceptions.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lnbits/exceptions.py b/lnbits/exceptions.py index 8e29b89b4..b7dafb234 100644 --- a/lnbits/exceptions.py +++ b/lnbits/exceptions.py @@ -7,6 +7,7 @@ from fastapi import FastAPI, HTTPException, Request from fastapi.exceptions import RequestValidationError from fastapi.responses import JSONResponse, RedirectResponse, Response from loguru import logger +from shortuuid import uuid from lnbits.settings import settings @@ -71,10 +72,11 @@ def register_exception_handlers(app: FastAPI): async def exception_handler(request: Request, exc: Exception): etype, _, tb = sys.exc_info() traceback.print_exception(etype, exc, tb) - logger.error(f"Exception: {exc!s}") + exception_id = uuid() + logger.error(f"Exception ID: {exception_id}\n{exc!s}") return render_html_error(request, exc) or JSONResponse( status_code=HTTPStatus.INTERNAL_SERVER_ERROR, - content={"detail": str(exc)}, + content={"detail": f"Unexpected error! ID: {exception_id}"}, ) @app.exception_handler(AssertionError)