Skip to content

Commit

Permalink
Merge pull request #441 from wri/gtc-2239
Browse files Browse the repository at this point in the history
GTC-2239 Better error message when trying to create API key with duplicate alias
  • Loading branch information
danscales authored Nov 22, 2023
2 parents 64e1cfb + be01890 commit 5881275
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 5881275

Please sign in to comment.