Skip to content

Commit ee59da3

Browse files
docs: fix code examples that crash at runtime and other inaccuracies (#5386)
1 parent 8464ab7 commit ee59da3

6 files changed

Lines changed: 13 additions & 16 deletions

File tree

docs/docs/api/Cookies.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* **path** `string` (optional)
1111
* **secure** `boolean` (optional)
1212
* **httpOnly** `boolean` (optional)
13-
* **sameSite** `'String'|'Lax'|'None'` (optional)
13+
* **sameSite** `'Strict'|'Lax'|'None'` (optional)
1414
* **unparsed** `string[]` (optional) Left over attributes that weren't parsed.
1515

1616
## `deleteCookie(headers, name[, attributes])`

docs/docs/api/Dispatcher.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ The `retry` interceptor allows you to customize the way your dispatcher handles
10161016

10171017
It accepts the same arguments as the [`RetryHandler` constructor](/docs/docs/api/RetryHandler.md).
10181018

1019-
**Example - Basic Redirect Interceptor**
1019+
**Example - Basic Retry Interceptor**
10201020

10211021
```js
10221022
const { Client, interceptors } = require("undici");
@@ -1112,7 +1112,7 @@ It represents a storage object for resolved DNS records.
11121112
**Example - Basic DNS Interceptor**
11131113

11141114
```js
1115-
const { Client, interceptors } = require("undici");
1115+
const { Agent, interceptors } = require("undici");
11161116
const { dns } = interceptors;
11171117

11181118
const client = new Agent().compose([
@@ -1128,7 +1128,7 @@ const response = await client.request({
11281128
**Example - DNS Interceptor and LRU cache as a storage**
11291129

11301130
```js
1131-
const { Client, interceptors } = require("undici");
1131+
const { Agent, interceptors } = require("undici");
11321132
const QuickLRU = require("quick-lru");
11331133
const { dns } = interceptors;
11341134

docs/docs/api/EnvHttpProxyAgent.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ import { setGlobalDispatcher, fetch, EnvHttpProxyAgent } from 'undici'
5252
const envHttpProxyAgent = new EnvHttpProxyAgent()
5353
setGlobalDispatcher(envHttpProxyAgent)
5454

55-
const { status, json } = await fetch('http://localhost:3000/foo')
55+
const response = await fetch('http://localhost:3000/foo')
5656

57-
console.log('response received', status) // response received 200
57+
console.log('response received', response.status) // response received 200
5858

59-
const data = await json() // data { foo: "bar" }
59+
const data = await response.json() // data { foo: "bar" }
6060
```
6161

6262
#### Example - Basic Proxy Request with global agent dispatcher
@@ -102,14 +102,11 @@ import { EnvHttpProxyAgent, fetch } from 'undici'
102102

103103
const envHttpProxyAgent = new EnvHttpProxyAgent()
104104

105-
const {
106-
status,
107-
json
108-
} = await fetch('http://localhost:3000/foo', { dispatcher: envHttpProxyAgent })
105+
const response = await fetch('http://localhost:3000/foo', { dispatcher: envHttpProxyAgent })
109106

110-
console.log('response received', status) // response received 200
107+
console.log('response received', response.status) // response received 200
111108

112-
const data = await json() // data { foo: "bar" }
109+
const data = await response.json() // data { foo: "bar" }
113110
```
114111

115112
## Instance Methods

docs/docs/api/Fetch.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ This API is implemented as per the standard, you can find documentation on [MDN]
2626

2727
This API is implemented as per the standard, you can find documentation on [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Request)
2828

29-
## Header
29+
## Headers
3030

3131
This API is implemented as per the standard, you can find documentation on [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Headers)
3232

docs/docs/api/H2CClient.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const server = createServer((req, res) => {
1717
})
1818

1919
server.listen()
20-
once(server, 'listening').then(() => {
20+
once(server, 'listening').then(async () => {
2121
const client = new H2CClient(`http://localhost:${server.address().port}/`)
2222

2323
const response = await client.request({ path: '/', method: 'GET' })

docs/docs/api/RetryHandler.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Extends: [`Dispatch.DispatchOptions`](/docs/docs/api/Dispatcher.md#parameter-dis
2020
#### `RetryOptions`
2121

2222
- **throwOnError** `boolean` (optional) - Disable to prevent throwing error on last retry attept, useful if you need the body on errors from server or if you have custom error handler.
23-
- **retry** `(err: Error, context: RetryContext, callback: (err?: Error | null) => void) => number | null` (optional) - Function to be called after every retry. It should pass error if no more retries should be performed.
23+
- **retry** `(err: Error, context: RetryContext, callback: (err?: Error | null) => void) => void` (optional) - Function to be called after every retry. It should pass error if no more retries should be performed.
2424
- **maxRetries** `number` (optional) - Maximum number of retries. Default: `5`
2525
- **maxTimeout** `number` (optional) - Maximum number of milliseconds to wait before retrying. Default: `30000` (30 seconds)
2626
- **minTimeout** `number` (optional) - Minimum number of milliseconds to wait before retrying. Default: `500` (half a second)

0 commit comments

Comments
 (0)