Skip to content

Commit d42ec89

Browse files
committed
📝 Better retry code snippets types
fixes #255
1 parent 3d189ba commit d42ec89

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

README.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ const w = wretch().middlewares([retry(), dedupe()])
677677
>
678678
> ```js
679679
> // Replace the default condition with a custom one to avoid retrying on 4xx errors:
680-
> until: (response, error) => response && (response.ok || (response.status >= 400 && response.status < 500))
680+
> until: (response, error) => !!response && (response.ok || (response.status >= 400 && response.status < 500))
681681
> ```
682682
683683
```js
@@ -690,20 +690,20 @@ wretch().middlewares([
690690
delayTimer: 500,
691691
delayRamp: (delay, nbOfAttempts) => delay * nbOfAttempts,
692692
maxAttempts: 10,
693-
until: (response, error) => response && response.ok,
694-
onRetry: null,
693+
until: (response, error) => !!response && response.ok,
694+
onRetry: undefined,
695695
retryOnNetworkError: false,
696696
resolveWithLatestResponse: false
697697
})
698-
])./* ... */
698+
])
699699
700700
// You can also return a Promise, which is useful if you want to inspect the body:
701701
wretch().middlewares([
702702
retry({
703703
until: response =>
704-
response.clone().json().then(body =>
704+
response?.clone().json().then(body =>
705705
body.field === 'something'
706-
)
706+
) || false
707707
})
708708
])
709709
```
@@ -723,7 +723,7 @@ wretch().middlewares([
723723
key: (url, opts) => opts.method + '@' + url,
724724
resolver: response => response.clone()
725725
})
726-
])./* ... */
726+
])
727727
```
728728
729729
### [Throttling Cache 🔗](https://elbywan.github.io/wretch/api/types/middlewares_throttlingCache.ThrottlingCacheMiddleware)
@@ -745,7 +745,7 @@ wretch().middlewares([
745745
condition: response => response.ok,
746746
flagResponseOnCacheHit: '__cached'
747747
})
748-
])./* ... */
748+
])
749749
```
750750
751751
### [Delay 🔗](https://elbywan.github.io/wretch/api/types/middlewares_delay.DelayMiddleware)
@@ -758,7 +758,7 @@ import { delay } from 'wretch/middlewares'
758758
759759
wretch().middlewares([
760760
delay(1000)
761-
])./* ... */
761+
])
762762
```
763763
764764
## Writing a Middleware

0 commit comments

Comments
 (0)