Skip to main content

undici

PropertyValue
Packageundici
Versions Covered>=5.0.0
Contract Version1.0.0
Statusproduction
Last Verified2026-02-26
Maintainercorpus-team

Installation

npm install undici

Covered Functions

This contract covers 2 function(s):

request()

Makes HTTP request using undici's low-level API

Import:

import { request } from 'undici';

Postconditions

What happens after calling this function:

🔴 ERROR - network-error-handling

Condition: network failure, DNS error, timeout, connection refused

Throws: Promise rejection with Error

Required Handling:

Use try-catch (async/await) or .catch() (promises)

📖 Source


fetch()

Makes HTTP request using Fetch API (similar to browser fetch)

Import:

import { fetch } from 'undici';

Postconditions

What happens after calling this function:

🔴 ERROR - network-error-handling

Condition: network failure, DNS error, timeout, connection refused, certificate errors

Throws: TypeError with 'fetch failed' message and cause property containing underlying error (UND_ERR_SOCKET, etc.)

Required Handling:

Use try-catch (async/await) or .catch() (promises)

📖 Source


Example: Proper Error Handling

import undici from 'undici';

async function example() {
try {
const result = await request(/* args */);
// Handle success
return result;
} catch (error) {
// Handle error according to contract postconditions
console.error('Error:', error);
throw error;
}
}

See Also