From 5ceb8639f9a5e215e1b9f7ae39a235a93b90d58a Mon Sep 17 00:00:00 2001 From: Tiago vasconcelos Date: Mon, 13 Jun 2022 16:18:16 +0100 Subject: [PATCH] clean up and comment --- lnbits/app.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lnbits/app.py b/lnbits/app.py index f4ebd93fe..1c9de5d7a 100644 --- a/lnbits/app.py +++ b/lnbits/app.py @@ -59,16 +59,19 @@ def create_app(config_object="lnbits.settings") -> FastAPI: async def validation_exception_handler( request: Request, exc: RequestValidationError ): + # Only the browser sends "text/html" request + # not fail proof, but everything else get's a JSON response if "text/html" in request.headers["accept"]: return template_renderer().TemplateResponse( "error.html", - {"request": request, "err": f"`{exc.errors()}` is not a valid UUID."}, - ) + {"request": request, "err": f"{exc.errors()} is not a valid UUID."}, + ) + return JSONResponse( status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, - content={"detail": exc.errors(), "body": exc.body}, + content={"detail": exc.errors()}, ) app.add_middleware(GZipMiddleware, minimum_size=1000)