Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
51 changes: 28 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -934,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.
Expand Down Expand Up @@ -1283,6 +1287,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
Expand Down Expand Up @@ -1407,29 +1435,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.
Expand Down
1 change: 1 addition & 0 deletions test/error_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
],
}


@pytest.mark.integration
@pytest.mark.asyncio
class TestErrorIntegration:
Expand Down