add json response for basic error

This commit is contained in:
Tiago vasconcelos 2022-06-15 16:20:20 +01:00
parent c4f9206c10
commit 626a93a46c

View file

@ -62,7 +62,7 @@ def create_app(config_object="lnbits.settings") -> FastAPI:
):
# 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",
@ -177,6 +177,13 @@ def register_exception_handlers(app: FastAPI):
etype, _, tb = sys.exc_info()
traceback.print_exception(etype, err, tb)
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": exc.errors()},
)