Improve failure devex (#2247)

This commit is contained in:
Suchintan
2025-04-30 13:21:10 -04:00
committed by GitHub
parent b55a5ee5f2
commit c069ebe6f9
5 changed files with 1127 additions and 1357 deletions

View File

@@ -674,6 +674,18 @@ class AgentDB:
LOG.error("UnexpectedError", exc_info=True)
raise
async def get_all_organizations(self) -> list[Organization]:
try:
async with self.Session() as session:
organizations = (await session.scalars(select(OrganizationModel))).all()
return [convert_to_organization(organization) for organization in organizations]
except SQLAlchemyError:
LOG.error("SQLAlchemyError", exc_info=True)
raise
except Exception:
LOG.error("UnexpectedError", exc_info=True)
raise
async def get_organization(self, organization_id: str) -> Organization | None:
try:
async with self.Session() as session:

View File

@@ -1,6 +1,7 @@
import time
from typing import Annotated
import structlog
from asyncache import cached
from cachetools import TTLCache
from fastapi import Header, HTTPException, status
@@ -15,6 +16,8 @@ from skyvern.forge.sdk.db.client import AgentDB
from skyvern.forge.sdk.models import TokenPayload
from skyvern.forge.sdk.schemas.organizations import Organization, OrganizationAuthTokenType
LOG = structlog.get_logger()
AUTHENTICATION_TTL = 60 * 60 # one hour
CACHE_SIZE = 128
ALGORITHM = "HS256"
@@ -91,6 +94,7 @@ async def _get_current_org_cached(x_api_key: str, db: AgentDB) -> Organization:
)
api_key_data = TokenPayload(**payload)
except (JWTError, ValidationError):
LOG.error("Error decoding JWT", exc_info=True)
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN,
detail="Could not validate credentials",