Found several code examples in the API docs that will throw errors if copied and run:
1. DNS interceptor examples use new Agent() without importing it (Dispatcher.md)
Both DNS interceptor examples import Client but use new Agent(). Running these gives ReferenceError: Agent is not defined.
// Line 1116 (wrong import)
const { Client, interceptors } = require("undici");
// Line 1119 (uses Agent without importing)
const client = new Agent().compose([dns({ ...opts })])
Same issue in the DNS + LRU cache example around line 1132.
Fix: Change import to const { Agent, interceptors } = require("undici")
2. H2CClient example uses await in non-async callback (H2CClient.md)
once(server, "listening").then(() => { // not async
const response = await client.request(...) // SyntaxError!
Fix: Add async to the callback: .then(async () => {
3. EnvHttpProxyAgent examples destructure json from Response (EnvHttpProxyAgent.md)
const { status, json } = await fetch(...)
const data = await json() // TypeError: json is not a function
json is a prototype method on Response — destructuring yields undefined. This appears in two examples.
Fix: Use const response = await fetch(...) then await response.json()
4. Cookies.md: sameSite type says "String" instead of "Strict"
* **sameSite** `"String"|"Lax"|"None"` (optional)
Fix: Change "String" to "Strict"
5. Dispatcher.md: Retry interceptor example heading says "Redirect" (copy-paste error)
The heading reads "Example - Basic Redirect Interceptor" but the code uses retry.
6. RetryHandler.md: retry callback return type says number | null but should be void
The RetryAgent.md correctly documents this as => void, but RetryHandler.md says => number | null.
7. Fetch.md: Section heading says Header (singular) instead of Headers
8. README.md claims undici does not support the Expect header, but expectContinue option exists for H2
Happy to open a PR fixing these.
Found several code examples in the API docs that will throw errors if copied and run:
1. DNS interceptor examples use
new Agent()without importing it (Dispatcher.md)Both DNS interceptor examples import
Clientbut usenew Agent(). Running these givesReferenceError: Agent is not defined.Same issue in the DNS + LRU cache example around line 1132.
Fix: Change import to
const { Agent, interceptors } = require("undici")2. H2CClient example uses
awaitin non-async callback (H2CClient.md)Fix: Add
asyncto the callback:.then(async () => {3. EnvHttpProxyAgent examples destructure
jsonfrom Response (EnvHttpProxyAgent.md)jsonis a prototype method onResponse— destructuring yieldsundefined. This appears in two examples.Fix: Use
const response = await fetch(...)thenawait response.json()4. Cookies.md:
sameSitetype says"String"instead of"Strict"Fix: Change
"String"to"Strict"5. Dispatcher.md: Retry interceptor example heading says "Redirect" (copy-paste error)
The heading reads "Example - Basic Redirect Interceptor" but the code uses
retry.6. RetryHandler.md:
retrycallback return type saysnumber | nullbut should bevoidThe
RetryAgent.mdcorrectly documents this as=> void, butRetryHandler.mdsays=> number | null.7. Fetch.md: Section heading says
Header(singular) instead ofHeaders8. README.md claims undici does not support the
Expectheader, butexpectContinueoption exists for H2Happy to open a PR fixing these.