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

Conversation

mrmauer
Copy link
Contributor

@mrmauer mrmauer commented Jan 15, 2025

After PR

This introduces graceful handling of rate-limit-specific error thrown when validating an end user's api key. For example, you can now do this

try:
    auth.validate_api_key(end_user_api_key)
    return {"message": "Success"}
except EndUserApiKeyRateLimitedException as e:
    print(e)
    # Example
    # {
    #   'error_code': 'rate_limit_exceeded', 
    #   'user_facing_error': 'Your api keys have hit the rate limit. Wait 58.134504795074 seconds.', 
    #   'wait_seconds': 58.134504795074
    # }
    return {"message": f"Please wait {e.args[0]['wait_seconds']} seconds before trying again."}
except EndUserApiKeyException as e:
    print(e)
    return {"message": "Invalid API key"}
except Exception as e:
    print(e)
    return {"message": "Something went wrong..."}

Bumps version to 4.1.0

Tests

Confirmed expected behavior within an example application.

Copy link
Contributor

@andrew-propelauth andrew-propelauth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@mrmauer mrmauer changed the title handle EndUserApiKeyRateLimitedException handle EndUserApiKeyRateLimitedException, 4.1.0 Jan 17, 2025
@mrmauer mrmauer merged commit 9a1abb3 into main Jan 17, 2025
1 check passed
@mrmauer mrmauer deleted the rate-limit-error branch January 17, 2025 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants