Skip to content

Commit 0faf900

Browse files
authored
Port over Retries with Backoff page from old site (#357)
1 parent 85b0fd0 commit 0faf900

File tree

3 files changed

+110
-1
lines changed

3 files changed

+110
-1
lines changed

fern/products/sdks/capabilities.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ layout: overview
3838
<Card title="OAuth Token Refresh" icon="fa-duotone fa-arrows-rotate">
3939
Fern supports OAuth as a first class citizen
4040
</Card>
41-
<Card title="Retries with Backoff" icon="fa-duotone fa-repeat">
41+
<Card title="Retries with Backoff" icon="fa-duotone fa-repeat" href="/sdks/deep-dives/retries-with-backoff">
4242
Automatically retry failed requests with exponential backoff
4343
</Card>
4444
<Card title="Webhook Signature Verification" icon="fa-duotone fa-key">
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
---
2+
title: Retries with Backoff
3+
description: Automatically retry failures with exponential backoff
4+
---
5+
6+
<Markdown src="/snippets/pro-callout.mdx" />
7+
8+
Fern SDKs will automatically retry failed requests with exponential backoff. A request will be retried as
9+
long as the request is deemed retryable and the number of retry attempts has
10+
not grown larger than the configured retry limit.
11+
12+
### Retryable status codes
13+
14+
A request is deemed retryable when any of the following HTTP status codes is returned:
15+
- [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
16+
- [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
17+
- [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors)
18+
19+
Note that you can configure the list of retryable status codes as well. For example,
20+
if you want to remove the `429` status code from the list of retryable status codes, you can do so.
21+
22+
### Overriding the retry limit
23+
24+
By default, the SDK will retry a failed request up to 2 times. SDK users can override the global
25+
default retry limit when instantiating the client.
26+
27+
<CodeBlocks>
28+
<CodeBlock title="TypeScript">
29+
```ts {4}
30+
import { ImdbClient } from "imdb";
31+
32+
const client = new ImdbClient({
33+
maxRetries: 1 // overrides the default retry limit to 1
34+
});
35+
```
36+
</CodeBlock>
37+
<CodeBlock title="Python">
38+
```python {4, 8}
39+
from imdb.client import Imdb, AsyncImdb
40+
41+
client = Imdb({
42+
max_retries: 1 # overrides the default retry limit to 1
43+
})
44+
45+
async_client = AsyncImdb({
46+
max_retries: 1 # overrides the default retry limit to 1
47+
})
48+
```
49+
</CodeBlock>
50+
<CodeBlock title="Java">
51+
```java {4}
52+
import com.imdb.ImdbClient;
53+
54+
ImdbClient client = new ImdbClient.Builder()
55+
.maxRetries(1) // overrides the default retry limit to 1
56+
.build();
57+
```
58+
</CodeBlock>
59+
<CodeBlock title="Go">
60+
```go {7}
61+
import (
62+
imdbclient "github.com/fern-workos/workos-go/client"
63+
"github.com/fern-workos/workos-go/option"
64+
)
65+
66+
client := imdbclient.NewClient(
67+
option.WithMaxAttempts(1), // overrides the default retry limit to 1
68+
)
69+
```
70+
</CodeBlock>
71+
</CodeBlocks>
72+
73+
It's also possible to override the retry limit on a per-request basis.
74+
75+
<CodeBlocks>
76+
<CodeBlock title="TypeScript">
77+
```ts {2}
78+
client.movie.get("tt0111161", {
79+
maxRetries: 3 // overrides the default retry limit to 3
80+
});
81+
```
82+
</CodeBlock>
83+
<CodeBlock title="Python">
84+
```python {2}
85+
client.movie.get("tt0111161", {
86+
max_retries: 3 // overrides the default retry limit to 3
87+
})
88+
```
89+
</CodeBlock>
90+
<CodeBlock title="Java">
91+
```java {2}
92+
client.movie().get("tt0111161", RequestOptions.builder()
93+
.maxRetries(3) // overrides the default retry limit to 3
94+
.build());
95+
```
96+
</CodeBlock>
97+
<CodeBlock title="Go">
98+
```go {4}
99+
response, err := client.Movies.Get(
100+
ctx,
101+
"tt0111161",
102+
option.WithMaxAttempts(1),
103+
)
104+
```
105+
</CodeBlock>
106+
</CodeBlocks>
107+

fern/products/sdks/sdks.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ navigation:
209209
hidden: true
210210
path: ./guides/self-host-fern-generators.mdx
211211
slug: self-host-generators
212+
- page: Retries with Backoff
213+
path: ./guides/retries-with-backoff.mdx
212214
- section: Reference
213215
contents:
214216
- page: generators.yml

0 commit comments

Comments
 (0)