diff --git a/src/backend/base/langflow/api/v1/store.py b/src/backend/base/langflow/api/v1/store.py index 313b0638b..7d0e9bff9 100644 --- a/src/backend/base/langflow/api/v1/store.py +++ b/src/backend/base/langflow/api/v1/store.py @@ -2,6 +2,7 @@ from typing import Annotated, List, Optional, Union from uuid import UUID from fastapi import APIRouter, Depends, HTTPException, Query +from loguru import logger from langflow.api.utils import check_langflow_version from langflow.services.auth import utils as auth_utils @@ -27,8 +28,11 @@ def get_user_store_api_key( ): if not user.store_api_key: raise HTTPException(status_code=400, detail="You must have a store API key set.") - decrypted = auth_utils.decrypt_api_key(user.store_api_key, settings_service) - return decrypted + try: + decrypted = auth_utils.decrypt_api_key(user.store_api_key, settings_service) + return decrypted + except Exception as e: + raise HTTPException(status_code=500, detail="Failed to decrypt API key. Please set a new one.") from e def get_optional_user_store_api_key( @@ -37,8 +41,12 @@ def get_optional_user_store_api_key( ): if not user.store_api_key: return None - decrypted = auth_utils.decrypt_api_key(user.store_api_key, settings_service) - return decrypted + try: + decrypted = auth_utils.decrypt_api_key(user.store_api_key, settings_service) + return decrypted + except Exception as e: + logger.error(f"Failed to decrypt API key: {e}") + return user.store_api_key @router.get("/check/") diff --git a/src/backend/base/langflow/main.py b/src/backend/base/langflow/main.py index 8893e60b0..5ba915df2 100644 --- a/src/backend/base/langflow/main.py +++ b/src/backend/base/langflow/main.py @@ -23,7 +23,11 @@ from langflow.utils.logger import configure class JavaScriptMIMETypeMiddleware(BaseHTTPMiddleware): async def dispatch(self, request: Request, call_next): - response = await call_next(request) + try: + response = await call_next(request) + except Exception as exc: + logger.error(exc) + raise exc if "files/" not in request.url.path and request.url.path.endswith(".js") and response.status_code == 200: response.headers["Content-Type"] = "text/javascript" return response