mirror of
https://github.com/lnbits/lnbits.git
synced 2025-06-12 09:51:06 +02:00
feat: mask unexcepted error and add a exception id (#3178)
This commit is contained in:
parent
3c4d186dba
commit
4071925f65
@ -7,6 +7,7 @@ from fastapi import FastAPI, HTTPException, Request
|
|||||||
from fastapi.exceptions import RequestValidationError
|
from fastapi.exceptions import RequestValidationError
|
||||||
from fastapi.responses import JSONResponse, RedirectResponse, Response
|
from fastapi.responses import JSONResponse, RedirectResponse, Response
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
from shortuuid import uuid
|
||||||
|
|
||||||
from lnbits.settings import settings
|
from lnbits.settings import settings
|
||||||
|
|
||||||
@ -71,10 +72,11 @@ def register_exception_handlers(app: FastAPI):
|
|||||||
async def exception_handler(request: Request, exc: Exception):
|
async def exception_handler(request: Request, exc: Exception):
|
||||||
etype, _, tb = sys.exc_info()
|
etype, _, tb = sys.exc_info()
|
||||||
traceback.print_exception(etype, exc, tb)
|
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(
|
return render_html_error(request, exc) or JSONResponse(
|
||||||
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
|
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
|
||||||
content={"detail": str(exc)},
|
content={"detail": f"Unexpected error! ID: {exception_id}"},
|
||||||
)
|
)
|
||||||
|
|
||||||
@app.exception_handler(AssertionError)
|
@app.exception_handler(AssertionError)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user