From ad3ec5e7050d84a4be9d9e857da6df083eb6b07c Mon Sep 17 00:00:00 2001 From: SoulPancake Date: Thu, 11 Dec 2025 18:46:27 +0530 Subject: [PATCH 1/2] chore: fix readme section for error handling and contributing guide --- CONTRIBUTING.md | 2 +- README.md | 48 ++++++++++++++++++---------------- test/error_integration_test.py | 1 + 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 81d44ff..b5aedf9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,7 +10,7 @@ Reading and following these guidelines will help us make the contribution proces * [Getting Started](#getting-started) * [Making Changes](#making-changes) * [Opening Issues](#opening-issues) - * [Submitting Pull Requests](#submitting-pull-requests) [Note: We are not accepting Pull Requests at this time!] + * [Submitting Pull Requests](#submitting-pull-requests) * [Getting in Touch](#getting-in-touch) * [Have a question or problem?](#have-a-question-or-problem) * [Vulnerability Reporting](#vulnerability-reporting) diff --git a/README.md b/README.md index 1222ccc..7020e67 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ This is an autogenerated python SDK for OpenFGA. It provides a wrapper around th - [Relationship Queries](#relationship-queries) - [Check](#check) - [Batch Check](#batch-check) + - [Client Batch Check](#client-batch-check) - [Expand](#expand) - [List Objects](#list-objects) - [Streamed List Objects](#streamed-list-objects) @@ -1283,6 +1284,30 @@ async def main(): ``` +### Error Handling + +The SDK provides comprehensive error handling with detailed error information and convenient helper methods. + +Key features: +- Operation context in error messages (e.g., `[write]`, `[check]`) +- Detailed error codes and messages from the API +- Helper methods for error categorization (`is_validation_error()`, `is_retryable()`, etc.) + +```python +from openfga_sdk.exceptions import ApiException + +try: + await client.write([tuple]) +except ApiException as e: + print(f"Error: {e}") # [write] HTTP 400 type 'invalid_type' not found (validation_error) [request-id: abc-123] + + if e.is_validation_error(): + print(f"Validation error: {e.error_message}") + elif e.is_retryable(): + print(f"Temporary error - retrying... (Request ID: {e.request_id})") +``` + + ### API Endpoints Class | Method | HTTP request | Description @@ -1407,29 +1432,6 @@ Class | Method | HTTP request | Description This SDK supports producing metrics that can be consumed as part of an [OpenTelemetry](https://opentelemetry.io/) setup. For more information, please see [the documentation](https://github.com/openfga/python-sdk/blob/main/docs/opentelemetry.md) -### Error Handling - -The SDK provides comprehensive error handling with detailed error information and convenient helper methods. - -Key features: -- Operation context in error messages (e.g., `[write]`, `[check]`) -- Detailed error codes and messages from the API -- Helper methods for error categorization (`is_validation_error()`, `is_retryable()`, etc.) - -```python -from openfga_sdk.exceptions import ApiException - -try: - await client.write([tuple]) -except ApiException as e: - print(f"Error: {e}") # [write] HTTP 400 type 'invalid_type' not found (validation_error) [request-id: abc-123] - - if e.is_validation_error(): - print(f"Validation error: {e.error_message}") - elif e.is_retryable(): - print(f"Temporary error - retrying... (Request ID: {e.request_id})") -``` - ## Contributing See [CONTRIBUTING](./CONTRIBUTING.md) for details. diff --git a/test/error_integration_test.py b/test/error_integration_test.py index 585804d..7139aea 100644 --- a/test/error_integration_test.py +++ b/test/error_integration_test.py @@ -53,6 +53,7 @@ ], } + @pytest.mark.integration @pytest.mark.asyncio class TestErrorIntegration: From 68af65eb54d2d78110c77b889cad17a626d97850 Mon Sep 17 00:00:00 2001 From: SoulPancake Date: Thu, 11 Dec 2025 19:11:51 +0530 Subject: [PATCH 2/2] fix: address copilot comment --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 7020e67..c424a14 100644 --- a/README.md +++ b/README.md @@ -935,6 +935,9 @@ response = await fga_client.batch_check(ClientBatchCheckRequest(checks=checks), # ] ``` +##### Client Batch Check + + If you are using an OpenFGA version less than 1.8.0, you can use `client_batch_check`, which calls `check` in parallel. It will return `allowed: false` if it encounters an error, and will return the error in the body. If 429s or 5xxs are encountered, the underlying check will retry up to 3 times before giving up.