Skip to content

Commit

Permalink
handle EndUserApiKeyRateLimitedException, 4.1.0 (#67)
Browse files Browse the repository at this point in the history
* handle EndUserApiKeyRateLimitedException

* make api-key-validation errors available for graceful handling

* bump to version 4.1.0
  • Loading branch information
mrmauer authored Jan 17, 2025
1 parent 13a3437 commit 9a1abb3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
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

0 comments on commit 9a1abb3

Please sign in to comment.