send json response basic error

This commit is contained in:
Tiago vasconcelos 2022-06-15 16:37:10 +01:00
parent 626a93a46c
commit 1ebba9f846

View file

@ -177,7 +177,7 @@ def register_exception_handlers(app: FastAPI):
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()
if "text/html" in request.headers["accept"]: if "text/html" in request.headers["accept"]:
return template_renderer().TemplateResponse( return template_renderer().TemplateResponse(
"error.html", {"request": request, "err": err} "error.html", {"request": request, "err": err}
@ -185,5 +185,5 @@ def register_exception_handlers(app: FastAPI):
return JSONResponse( return JSONResponse(
status_code=HTTPStatus.NO_CONTENT, status_code=HTTPStatus.NO_CONTENT,
content={"detail": exc.errors()}, content={"detail": exc},
) )