Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle EndUserApiKeyRateLimitedException, 4.1.0 #67

Merged
merged 3 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion propelauth_py/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@
wrap_validate_access_token_and_get_user_with_org_by_minimum_role,
wrap_validate_access_token_and_get_user_with_org_by_permission,
)
from propelauth_py.errors import ForbiddenException, UnauthorizedException
from propelauth_py.errors import (
ForbiddenException,
UnauthorizedException,
EndUserApiKeyRateLimitedException,
EndUserApiKeyException,
)
from propelauth_py.types.login_method import (
EmailConfirmationLinkLoginMethod,
GeneratedFromBackendApiLoginMethod,
Expand Down
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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

setup(
name="propelauth-py",
version="4.0.2",
version="4.1.0",
description="A python authentication library",
long_description=README,
long_description_content_type="text/markdown",
Expand Down
Loading