diff --git a/CHANGELOG.md b/CHANGELOG.md index 168328ce..41fca2a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ -## 0.0.44-dev1 +## 0.0.44 * Bump unstructured to 0.10.14 * Improve parallel mode retry handling +* Improve logging during error handling. We don't need to log stack traces for expected errors. ## 0.0.43 diff --git a/prepline_general/api/app.py b/prepline_general/api/app.py index 77d23b7d..9220f4ea 100644 --- a/prepline_general/api/app.py +++ b/prepline_general/api/app.py @@ -18,18 +18,16 @@ openapi_url="/general/openapi.json", ) +# Note(austin) - This logger just dumps exceptions +# We'd rather handle those below +uvicorn_logger = logging.getLogger("uvicorn.error") +uvicorn_logger.disabled = True + # Catch all HTTPException for uniform logging and response @app.exception_handler(HTTPException) async def http_error_handler(request: Request, e: HTTPException): - trace = traceback.format_exc() - - # Note(austin) - If ENV is set, dump the stack in json - # for nicer parsing. Soon we'll just have a json logger do this. - if os.environ.get("ENV") in ["dev", "prod"]: - trace = json.dumps(trace) - - logger.error(trace) + logger.error(e.detail) return JSONResponse( status_code=e.status_code, @@ -38,9 +36,18 @@ async def http_error_handler(request: Request, e: HTTPException): # Note(austin) - Convert any other errors to HTTPException -# to be handled above +# to be handled above, and log the stack trace @app.exception_handler(Exception) async def error_handler(request: Request, e: Exception): + trace = traceback.format_exc() + + # Note(austin) - If ENV is set, dump the stack in json + # for nicer parsing. Soon we'll just have a json logger do this. + if os.environ.get("ENV") in ["dev", "prod"]: + trace = json.dumps(trace) + + logger.error(trace) + error = HTTPException( status_code=500, detail=str(e)