-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Description
As identified in PR #32 review, the current OAuth2 implementation uses generic exception catching which could be more specific to help developers handle different failure scenarios.
Current State
- Generic Exception and ValueError types used
- Limited ability to handle specific OAuth2 error cases programmatically
Proposed Solution
Create specific exception types for common OAuth2 failures:
class OAuth2Error(Exception):
'''Base exception for OAuth2 operations'''
pass
class InvalidGrantError(OAuth2Error):
'''The provided authorization grant is invalid, expired, or revoked'''
pass
class InvalidClientError(OAuth2Error):
'''Client authentication failed'''
pass
class TokenExpiredError(OAuth2Error):
'''The access token has expired'''
pass
class InvalidScopeError(OAuth2Error):
'''The requested scope is invalid, unknown, or malformed'''
pass
class RateLimitError(OAuth2Error):
'''OAuth2 endpoint rate limit exceeded'''
passImplementation Notes
- Map OAuth2 error responses to specific exceptions
- Maintain backward compatibility by inheriting from base OAuth2Error
- Include error details from API response in exception
Benefits
- Better error handling in user applications
- Clearer debugging experience
- Follows Python best practices for exception hierarchy
Example Usage
try:
token = await exchange_authorization_code_async(...)
except InvalidGrantError:
# Handle expired/invalid authorization code
pass
except TokenExpiredError:
# Trigger token refresh
pass
except OAuth2Error as e:
# Handle other OAuth2 errors
logger.error(f'OAuth2 error: {e}')References
- PR Release v0.2.0b1 - First Beta Release #32 review feedback
- OAuth2 RFC error types: https://tools.ietf.org/html/rfc6749#section-5.2
Metadata
Metadata
Assignees
Labels
No labels