You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Enhanced error handling with convenience properties and helper methods
This commit significantly improves error handling in the Python SDK by adding:
1. Convenience Properties:
- Direct access to error code via e.code (instead of e.parsed_exception.code)
- Direct access to error message via e.error_message
- Direct access to request ID via e.request_id
- Direct access to store ID via e.store_id
- Direct access to authorization model ID via e.authorization_model_id
2. Operation Context:
- Added operation_name parameter to ApiException and all subclasses
- Exceptions now track which operation failed (e.g., "Check", "Write")
- operation_name propagated through api_client call stack
3. Helper Methods:
- is_validation_error() - Check if error is a validation error
- is_not_found_error() - Check if error is a not found error
- is_authentication_error() - Check if error is an authentication error
- is_authorization_error() - Check if error is an authorization error
- is_rate_limit_error() - Check if error is a rate limit error
- is_server_error() - Check if error is a server error
- is_retryable() - Check if error should be retried
4. Enhanced Error Messages:
- __str__ method now includes operation name, error code, message,
request ID, store ID, and authorization model ID
- More readable and informative error output
5. Testing:
- Added comprehensive unit tests (17 test cases)
- Added integration tests against real OpenFGA server
- Docker Compose setup for integration testing
- Test documentation and run script
Changes are fully backwards compatible - existing code continues to work.
Files modified:
- openfga_sdk/exceptions.py: Enhanced ApiException and subclasses
- openfga_sdk/api_client.py: Added operation_name parameter propagation
- openfga_sdk/sync/api_client.py: Added operation_name parameter propagation
Files added:
- test/error_handling_improvements_test.py: Unit tests
- test/integration_error_handling_test.py: Integration tests
- docker-compose.integration-test.yml: Test infrastructure
- run_integration_tests.sh: Helper script
- test/README_INTEGRATION_TESTS.md: Test documentation
0 commit comments