class NothingToRespondException(Exception):
def __init__(self, stage: str):
self.detail = "No answer to return while executing " + stage + ", try adjusting threshold"
async def nothing_to_respond_exception_handler(request: Request, exc: NothingToRespondException):
return JSONResponse(
status_code=404,
content={"message": exc.detail},
)
Python fastapi 의 exceptions handler를 만들 때
자꾸
RuntimeError: Response content longer than Content-Length in Uvicorn, for status codes without body
이딴 애러를 내서 봤더니,
Status CODE 200대, ex.204 ...
는 에러로 취급되지 않아서 에러메시지를 못쓰게 되어 있더라.
404 code로 바꿔 해결