Files
SnowLuma/.pnpm-store/v11/files/16/b5679dd80aa17c3473ad87a752b839de1542919a7301fc0ae75355b8094ac8a7d86a2a3bd1490b03dcd31acefe22d157d0483e23c319ff0b12647728575983
T
TanTan 2a69b23b47
Dev Build / cleanup (push) Waiting to run
Dev Build / typecheck (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

64 lines
1.6 KiB
Plaintext

# MockErrors
<!--introduced_in=v4.0.0-->
<!--type=module-->
<!-- source_link=lib/mock/mock-errors.js -->
> Stability: 2 - Stable
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:
```js
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`
<!-- YAML
added: v4.0.0
-->
* Extends: {UndiciError}
Thrown 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.
* `name` {string} Always `'MockNotMatchedError'`.
* `code` {string} Always `'UND_MOCK_ERR_MOCK_NOT_MATCHED'`.
### `new MockNotMatchedError([message])`
<!-- YAML
added: v4.0.0
-->
* `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.
```js
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')
}
}
```
[`MockAgent`]: MockAgent.md#class-mockagent
[`UndiciError`]: Errors.md#class-undicierror