add api key expired message to the 403 when an api key is expired/invalid (#532)

This commit is contained in:
Kerem Yilmaz
2024-06-29 23:55:05 -07:00
committed by GitHub
parent 6a6119b406
commit 27da621f44
2 changed files with 17 additions and 9 deletions

View File

@@ -109,6 +109,7 @@ async def _get_current_org_cached(x_api_key: str, db: AgentDB) -> Organization:
organization_id=organization.organization_id,
token_type=OrganizationAuthTokenType.api,
token=x_api_key,
valid=None,
)
if not api_key_db_obj:
raise HTTPException(
@@ -116,6 +117,12 @@ async def _get_current_org_cached(x_api_key: str, db: AgentDB) -> Organization:
detail="Invalid credentials",
)
if api_key_db_obj.valid is False:
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN,
detail="Your API key has expired. Please retrieve the latest one from https://app.skyvern.com/settings",
)
# set organization_id in skyvern context and log context
context = skyvern_context.current()
if context: