mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-26 01:12:21 +00:00
fix(mcp): return 409 on user-fields conflict for OAuth credential POST
store_user_oauth_credential raises ValueError when the (user, server) row already holds a non-OAuth2 payload, which now includes user-fields blobs. Catch it in the explicit credential-POST endpoint and surface 409 instead of letting management_endpoint_wrapper re-raise as 500, mirroring the existing handling on the BYOK and user-field-values POST endpoints.
This commit is contained in:
parent
501afd2361
commit
4618e28046
1 changed files with 19 additions and 9 deletions
|
|
@ -2009,15 +2009,25 @@ if MCP_AVAILABLE:
|
|||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail={"error": "User ID not found in token"},
|
||||
)
|
||||
await store_user_oauth_credential(
|
||||
prisma_client,
|
||||
user_id,
|
||||
server_id,
|
||||
payload.access_token,
|
||||
refresh_token=payload.refresh_token,
|
||||
expires_in=payload.expires_in,
|
||||
scopes=payload.scopes,
|
||||
)
|
||||
try:
|
||||
await store_user_oauth_credential(
|
||||
prisma_client,
|
||||
user_id,
|
||||
server_id,
|
||||
payload.access_token,
|
||||
refresh_token=payload.refresh_token,
|
||||
expires_in=payload.expires_in,
|
||||
scopes=payload.scopes,
|
||||
)
|
||||
except ValueError as e:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_409_CONFLICT,
|
||||
detail={
|
||||
"error": "credential_conflict",
|
||||
"message": str(e),
|
||||
"server_id": server_id,
|
||||
},
|
||||
)
|
||||
# Read back the persisted record so the response reflects the stored
|
||||
# expires_at rather than recomputing it here (which could diverge by
|
||||
# milliseconds or if the storage logic ever adds a grace period).
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue