Skip to content

Commit

Permalink
handle EndUserApiKeyRateLimitedException
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmauer committed Jan 15, 2025
1 parent 13a3437 commit adc0c29
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion propelauth_py/api/end_user_api_keys.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Optional
import requests
from propelauth_py.api import _ApiKeyAuth, _is_valid_hex, remove_bearer_if_exists
from propelauth_py.errors import EndUserApiKeyException, EndUserApiKeyNotFoundException
from propelauth_py.errors import EndUserApiKeyException, EndUserApiKeyNotFoundException, EndUserApiKeyRateLimitedException
from propelauth_py.types.end_user_api_keys import ApiKeyFull, ApiKeyResultPage, ApiKeyNew, ApiKeyValidation
from propelauth_py.types.user import UserMetadata, OrgFromApiKey
from propelauth_py.user import OrgMemberInfo
Expand Down Expand Up @@ -204,6 +204,8 @@ def _validate_api_key(auth_url, integration_api_key, api_key_token) -> ApiKeyVal
raise EndUserApiKeyException(response.json())
elif response.status_code == 404:
raise EndUserApiKeyNotFoundException()
elif response.status_code == 429:
raise EndUserApiKeyRateLimitedException(response.json())
elif not response.ok:
raise RuntimeError("Unknown error when validating end user api key")

Expand Down
7 changes: 7 additions & 0 deletions propelauth_py/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ def __init__(self, field_to_errors):
class EndUserApiKeyNotFoundException(Exception):
pass

class EndUserApiKeyRateLimitedException(Exception):
def __init__(self, field_to_errors):
self.wait_seconds = field_to_errors.get("wait_seconds")
self.user_facing_error = field_to_errors.get("user_facing_error")
self.error_code = field_to_errors.get("error_code")
self.field_to_errors = field_to_errors


class UnauthorizedException(Exception):
def __init__(self, message):
Expand Down

0 comments on commit adc0c29

Please sign in to comment.