Stability: 2Stable
undici raises a dedicated error when a mocked request cannot be matched against
any registered interceptor. The mock error classes are exposed through the
mockErrors namespace of the package:
import { mockErrors } from 'undici'
if (err instanceof mockErrors.MockNotMatchedError) {
// handle an unmatched mocked request
}Like every other undici error, the classes in this namespace extend
UndiciError and carry a stable code string, so failures can be
distinguished programmatically without relying on the error message.
class MockNotMatchedError extends UndiciErrorThrown when a request issued against a MockAgent does not match any of the
registered mock dispatches and the agent is configured to disable net connect.
Attributes
new MockNotMatchedError(message?): voidAttributes
message?:
<string>The error message.
Default:
'The request does not match any registered mock dispatches'
.Creates a new MockNotMatchedError. When message is omitted, a default
message describing the unmatched request is used.
import { mockErrors } from 'undici'
try {
// ... perform a request that no mock matches ...
} catch (err) {
if (err.code === 'UND_MOCK_ERR_MOCK_NOT_MATCHED') {
console.error('No registered mock matched the request')
}
}