Skip to content

Commit d46a3aa

Browse files
committed
logging dbid fix
1 parent 295665a commit d46a3aa

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

impl/main.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,20 +253,23 @@ async def shutdown_event():
253253

254254
@app.exception_handler(Exception)
255255
async def generic_exception_handler(request: Request, exc: Exception):
256-
# Log the error
257-
logger.error(f"Unexpected error: {exc} for request url {request.url} request method {request.method} request path params {request.path_params} request query params {request.query_params} base_url {request.base_url}")
256+
# Log the error with safe dbid access
257+
dbid = getattr(request.state, "dbid", None)
258+
logger.error(f"Unexpected error: {exc} for request url {request.url} request method {request.method} request path params {request.path_params} request query params {request.query_params} base_url {request.base_url}" + (f", dbid: {dbid}" if dbid else ""))
258259

259260
if isinstance(exc, HTTPException):
260-
raise exec
261-
# Return an error response, not sure if we want to return all errors but at least this surfaces things like bad embedding model. Though that should be a 4xx error?
261+
raise exc
262+
# Return an error response
262263
return JSONResponse(
263264
status_code=500, content={"message": str(exc)}
264265
)
265266

266267

267268
@app.exception_handler(RequestValidationError)
268269
async def validation_exception_handler(request: Request, exc: RequestValidationError):
269-
logging.error(f"Validation error for request: {request.url}, dbid: {request.state.dbid}")
270+
dbid = getattr(request.state, "dbid", None)
271+
if dbid:
272+
logging.error(f"Validation error for request: {request.url}, dbid: {dbid}")
270273
logging.error(f"Body: {exc.body}")
271274
logging.error(f"Validation error: {exc} for request url {request.url} request method {request.method} request path params {request.path_params} request query params {request.query_params} base_url {request.base_url}")
272275
logging.error(f"Errors: {exc.errors()}")

0 commit comments

Comments
 (0)