MCPcopy Index your code
hub / github.com/simstudioai/sim / createErrorFetch

Function createErrorFetch

packages/testing/src/builders/tool-tester.builder.ts:87–108  ·  view source on GitHub ↗
(errorMessage: string, status = 400)

Source from the content-addressed store, hash-verified

85 * Creates a mock error fetch function.
86 */
87export function createErrorFetch(errorMessage: string, status = 400) {
88 const error = new Error(errorMessage)
89 ;(error as Error & { status: number }).status = status
90
91 if (status < 0) {
92 const mockFn = vi.fn().mockRejectedValue(error)
93 ;(mockFn as MockFetch).preconnect = vi.fn()
94 return mockFn as MockFetch
95 }
96
97 const mockFetchConfig: MockFetchResponse = {
98 ok: false,
99 status,
100 statusText: errorMessage,
101 json: { error: errorMessage, message: errorMessage },
102 }
103
104 const baseMockFetch = createBaseMockFetch(mockFetchConfig)
105 ;(baseMockFetch as MockFetch).preconnect = vi.fn()
106
107 return baseMockFetch as MockFetch
108}
109
110/**
111 * Helper class for testing tools with controllable mock responses

Callers 1

setupErrorMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected