diff --git a/propelauth_py/api/end_user_api_keys.py b/propelauth_py/api/end_user_api_keys.py index 4840ab4..8de69ff 100644 --- a/propelauth_py/api/end_user_api_keys.py +++ b/propelauth_py/api/end_user_api_keys.py @@ -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 @@ -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") diff --git a/propelauth_py/errors.py b/propelauth_py/errors.py index ec55673..3d59d01 100644 --- a/propelauth_py/errors.py +++ b/propelauth_py/errors.py @@ -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):