Skip to content

Commit 1a34d84

Browse files
jordanrfrazierautofix-ci[bot]ogabrielluiz
authored
fix: log session scope errors at appropriate error (#10546)
* Log db session scope errors at appropriate error * [autofix.ci] apply automated fixes * uses http status codes * [autofix.ci] apply automated fixes * [autofix.ci] apply automated fixes (attempt 2/3) --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>
1 parent bfbaeab commit 1a34d84

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

  • src/backend/base/langflow/services

src/backend/base/langflow/services/deps.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from __future__ import annotations
22

33
from contextlib import asynccontextmanager
4+
from http import HTTPStatus
45
from typing import TYPE_CHECKING
56

7+
from fastapi import HTTPException
68
from lfx.log.logger import logger
79

810
from langflow.services.schema import ServiceType
@@ -179,8 +181,20 @@ async def session_scope() -> AsyncGenerator[AsyncSession, None]:
179181
yield session
180182
await session.commit()
181183
except Exception as e:
182-
await logger.aexception("An error occurred during the session scope.", exception=e)
183184
await session.rollback()
185+
186+
# Log at appropriate level based on error type
187+
if isinstance(e, HTTPException):
188+
if HTTPStatus.BAD_REQUEST.value <= e.status_code < HTTPStatus.INTERNAL_SERVER_ERROR.value:
189+
# Client errors (4xx) - log at info level
190+
await logger.ainfo(f"Client error during session scope: {e.status_code}: {e.detail}")
191+
else:
192+
# Server errors (5xx) or other - log at error level
193+
await logger.aexception("An error occurred during the session scope.", exception=e)
194+
else:
195+
# Non-HTTP exceptions - log at error level
196+
await logger.aexception("An error occurred during the session scope.", exception=e)
197+
184198
raise
185199

186200

0 commit comments

Comments
 (0)