Skip to content

Commit

Permalink
GTC-2239 Better error message for creating API key with duplicate alias
Browse files Browse the repository at this point in the history
Give a good error code/message if user is specifying an alias that
exists for another one of his API keys.
  • Loading branch information
danscales committed Nov 22, 2023
1 parent 64e1cfb commit be01890
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/routes/authentication/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ async def create_api_key(
detail="Domain name did not match the request origin or referrer.",
)

# Give a good error code/message if user is specifying an alias that exists for
# another one of his API keys.
prev_keys: List[ORMApiKey] = await api_keys.get_api_keys_from_user(user_id=user_id)
for key in prev_keys:
if key.alias == api_key_data.alias:
raise HTTPException(
status_code=409,
detail="Key with specified alias already exists; use a different alias"
)

row: ORMApiKey = await api_keys.create_api_key(user_id=user_id, **input_data)

is_internal = api_key_is_internal(
Expand Down

0 comments on commit be01890

Please sign in to comment.