mirror of
https://github.com/lnbits/lnbits.git
synced 2025-07-01 02:51:29 +02:00
Merge pull request #671 from talvasconcelos/fix/error_response
Hotfix for JSON response
This commit is contained in:
@ -62,7 +62,7 @@ def create_app(config_object="lnbits.settings") -> FastAPI:
|
|||||||
):
|
):
|
||||||
# Only the browser sends "text/html" request
|
# Only the browser sends "text/html" request
|
||||||
# not fail proof, but everything else get's a JSON response
|
# not fail proof, but everything else get's a JSON response
|
||||||
|
|
||||||
if "text/html" in request.headers["accept"]:
|
if "text/html" in request.headers["accept"]:
|
||||||
return template_renderer().TemplateResponse(
|
return template_renderer().TemplateResponse(
|
||||||
"error.html",
|
"error.html",
|
||||||
@ -174,9 +174,17 @@ def register_exception_handlers(app: FastAPI):
|
|||||||
@app.exception_handler(Exception)
|
@app.exception_handler(Exception)
|
||||||
async def basic_error(request: Request, err):
|
async def basic_error(request: Request, err):
|
||||||
print("handled error", traceback.format_exc())
|
print("handled error", traceback.format_exc())
|
||||||
|
print("ERROR:", err)
|
||||||
etype, _, tb = sys.exc_info()
|
etype, _, tb = sys.exc_info()
|
||||||
traceback.print_exception(etype, err, tb)
|
traceback.print_exception(etype, err, tb)
|
||||||
exc = traceback.format_exc()
|
exc = traceback.format_exc()
|
||||||
return template_renderer().TemplateResponse(
|
|
||||||
"error.html", {"request": request, "err": err}
|
if "text/html" in request.headers["accept"]:
|
||||||
|
return template_renderer().TemplateResponse(
|
||||||
|
"error.html", {"request": request, "err": err}
|
||||||
|
)
|
||||||
|
|
||||||
|
return JSONResponse(
|
||||||
|
status_code=HTTPStatus.NO_CONTENT,
|
||||||
|
content={"detail": err},
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user