handle all exceptions during user retrieving
This commit is contained in:
parent
5686a6fd63
commit
83425b09cd
1 changed files with 8 additions and 2 deletions
|
|
@ -4,7 +4,6 @@ from fastapi.security import APIKeyHeader, APIKeyQuery, OAuth2PasswordBearer
|
||||||
from jose import JWTError, jwt
|
from jose import JWTError, jwt
|
||||||
from typing import Annotated, Coroutine, Optional, Union
|
from typing import Annotated, Coroutine, Optional, Union
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
from starlette.requests import Request
|
|
||||||
from langflow.services.database.models.api_key.api_key import ApiKey
|
from langflow.services.database.models.api_key.api_key import ApiKey
|
||||||
from langflow.services.database.models.api_key.crud import check_key
|
from langflow.services.database.models.api_key.crud import check_key
|
||||||
from langflow.services.database.models.user.user import User
|
from langflow.services.database.models.user.user import User
|
||||||
|
|
@ -77,7 +76,9 @@ async def get_current_user(
|
||||||
) -> User:
|
) -> User:
|
||||||
try:
|
try:
|
||||||
return await get_current_user_by_jwt(token, db)
|
return await get_current_user_by_jwt(token, db)
|
||||||
except HTTPException:
|
except HTTPException as exc:
|
||||||
|
if not query_param and not header_param:
|
||||||
|
raise exc
|
||||||
user = await api_key_security(query_param, header_param, db)
|
user = await api_key_security(query_param, header_param, db)
|
||||||
if user:
|
if user:
|
||||||
return user
|
return user
|
||||||
|
|
@ -85,6 +86,11 @@ async def get_current_user(
|
||||||
status_code=status.HTTP_403_FORBIDDEN,
|
status_code=status.HTTP_403_FORBIDDEN,
|
||||||
detail="Invalid or missing API key",
|
detail="Invalid or missing API key",
|
||||||
)
|
)
|
||||||
|
except Exception as exc:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||||
|
detail=f"Internal server error: {exc}",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def get_current_user_by_jwt(
|
async def get_current_user_by_jwt(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue