MCPcopy
hub / github.com/mswjs/msw / resolve

Function resolve

src/core/experimental/frames/http-frame.ts:137–278  ·  view source on GitHub ↗
(
    handlers: Array<RequestHandler>,
    onUnhandledFrame: UnhandledFrameHandle,
    resolutionContext?: NetworkFrameResolutionContext,
  )

Source from the content-addressed store, hash-verified

135 }
136
137 public async resolve(
138 handlers: Array<RequestHandler>,
139 onUnhandledFrame: UnhandledFrameHandle,
140 resolutionContext?: NetworkFrameResolutionContext,
141 ): Promise<boolean | null> {
142 const { id: requestId, request } = this.data
143 const requestCloneForLogs = resolutionContext?.quiet
144 ? null
145 : request.clone()
146
147 this.events.emit(new RequestEvent('request:start', { requestId, request }))
148
149 // Requests wrapped in explicit "bypass(request)".
150 if (shouldBypassRequest(request)) {
151 this.events.emit(new RequestEvent('request:end', { requestId, request }))
152 this.passthrough()
153 return null
154 }
155
156 const [lookupError, lookupResult] = await until(() => {
157 return executeHandlers({
158 requestId,
159 request,
160 handlers,
161 resolutionContext: {
162 baseUrl: resolutionContext?.baseUrl?.toString(),
163 quiet: resolutionContext?.quiet,
164 },
165 })
166 })
167
168 if (lookupError != null) {
169 if (
170 !this.events.emit(
171 new UnhandledExceptionEvent('unhandledException', {
172 error: lookupError,
173 requestId,
174 request,
175 }),
176 )
177 ) {
178 // Surface the error to the developer since they haven't handled it.
179 console.error(lookupError)
180 devUtils.error(
181 'Encountered an unhandled exception during the handler lookup for "%s %s". Please see the original error above.',
182 request.method,
183 request.url,
184 )
185 }
186
187 this.errorWith(lookupError)
188 return null
189 }
190
191 // No matching handlers.
192 if (lookupResult == null) {
193 this.events.emit(
194 new RequestEvent('request:unhandled', {

Calls 12

shouldBypassRequestFunction · 0.90
executeHandlersFunction · 0.90
isPassthroughResponseFunction · 0.90
storeResponseCookiesFunction · 0.90
cloneMethod · 0.80
toStringMethod · 0.80
passthroughMethod · 0.45
errorMethod · 0.45
errorWithMethod · 0.45
respondWithMethod · 0.45
logMethod · 0.45

Tested by 4

stopWorkerOnFunction · 0.40
getStreamResponseFunction · 0.40
nextFunction · 0.40

Used in the wild real call sites across dependent graphs

searching dependent graphs…