Skip to content

Commit 3903c32

Browse files
committed
update README
1 parent 5599fa2 commit 3903c32

1 file changed

Lines changed: 42 additions & 4 deletions

File tree

README.md

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -965,9 +965,25 @@ fgaClient.writeAssertions(assertions, options).get();
965965
966966
### Retries
967967
968-
If a network request fails with a 429 or 5xx error from the server, the SDK will automatically retry the request up to 3 times with a minimum wait time of 100 milliseconds between each attempt.
968+
The SDK implements RFC 9110 compliant retry behavior with support for the `Retry-After` header. By default, the SDK will automatically retry failed requests up to **15 times** with intelligent delay calculation.
969969
970-
To customize this behavior, call `maxRetries` and `minimumRetryDelay` on the `ClientConfiguration` builder. `maxRetries` determines the maximum number of retries (up to 15), while `minimumRetryDelay` sets the minimum wait time between retries in milliseconds.
970+
#### Retry Behavior
971+
972+
**Rate Limiting (429 errors):** Always retried regardless of HTTP method.
973+
974+
**Server Errors (5xx):** Retry behavior depends on the HTTP method:
975+
- **Read operations** (GET, HEAD, OPTIONS): Always retried on 5xx errors
976+
- **Write operations** (POST, PUT, PATCH, DELETE): Only retried on 5xx errors when the server provides a `Retry-After` header
977+
978+
#### Delay Calculation
979+
980+
1. **Retry-After header present**: Uses the server-specified delay (supports both integer seconds and HTTP-date formats)
981+
2. **No Retry-After header**: Uses exponential backoff with jitter (base delay: 2^retryCount * 500ms, capped at 120 seconds)
982+
3. **Minimum delay**: Respects the configured `minimumRetryDelay` as a floor value
983+
984+
#### Configuration
985+
986+
Customize retry behavior using the `ClientConfiguration` builder:
971987
972988
```java
973989
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -981,15 +997,37 @@ public class Example {
981997
.apiUrl(System.getenv("FGA_API_URL")) // If not specified, will default to "http://localhost:8080"
982998
.storeId(System.getenv("FGA_STORE_ID")) // Not required when calling createStore() or listStores()
983999
.authorizationModelId(System.getenv("FGA_MODEL_ID")) // Optional, can be overridden per request
984-
.maxRetries(3) // retry up to 3 times on API requests
985-
.minimumRetryDelay(250); // wait a minimum of 250 milliseconds between requests
1000+
.maxRetries(15) // retry up to 15 times on API requests (default: 15)
1001+
.minimumRetryDelay(100); // minimum wait time between retries in milliseconds (default: 100ms)
9861002

9871003
var fgaClient = new OpenFgaClient(config);
9881004
var response = fgaClient.readAuthorizationModels().get();
9891005
}
9901006
}
9911007
```
9921008

1009+
#### Error Handling with Retry Information
1010+
1011+
When handling errors, you can access the `Retry-After` header value for debugging or custom retry logic:
1012+
1013+
```java
1014+
try {
1015+
var response = fgaClient.check(request).get();
1016+
} catch (ExecutionException e) {
1017+
if (e.getCause() instanceof FgaError) {
1018+
FgaError error = (FgaError) e.getCause();
1019+
1020+
// Access Retry-After header if present
1021+
String retryAfter = error.getRetryAfterHeader();
1022+
if (retryAfter != null) {
1023+
System.out.println("Server requested retry after: " + retryAfter + " seconds");
1024+
}
1025+
1026+
System.out.println("Error: " + error.getMessage());
1027+
}
1028+
}
1029+
```
1030+
9931031
### API Endpoints
9941032

9951033
| Method | HTTP request | Description |

0 commit comments

Comments
 (0)