Connectum API Reference / @connectum/test-fixtures / index / createMockNextError
Function: createMockNextError() ​
createMockNextError(
code,message?):any
Defined in: mock-next.ts:176
Create a mock next handler that always throws a ConnectError.
Useful for testing how interceptors handle downstream failures.
Parameters ​
code ​
Code
The gRPC status code for the error.
message? ​
string
Human-readable error message. Defaults to "Mock error".
Returns ​
any
A spy-enabled async function that throws on every call.
Throws ​
TypeError when code is not a Code of @connectrpc/connect (an integer from 1 to 16).
Example ​
ts
import { Code } from "@connectrpc/connect";
import { createMockNextError } from "@connectum/testing";
const next = createMockNextError(Code.NotFound, "user not found");
await next({}).catch((err) => {
// err instanceof ConnectError => true
// err.code => Code.NotFound
});