Repository navigation
onUnhandledFrame: frame.data is unknown (frame.protocol check)
#2823
|
In docs (https://mswjs.io/api/setup-server/listen#onunhandledframe) i see new way to handle unhandled http requests: server.listen({
onUnhandledFrame({ frame }) {
if (frame.protocol === 'http') {
const { request } = frame.data
console.log('Unhandled %s %s', request.method, request.url)
}
},
})But frame is I see |
Replies: 1 comment 2 replies
|
Import it with: Then inside In v3.0.3, Sources: export, base type, and MSW's own use of this guard. This is an experimental export, so check it when upgrading MSW. |
HttpNetworkFrameis exported frommsw/experimental. You can useframe instanceof HttpNetworkFrameinstead of checkingframe.protocol === 'http'.Import it with:
Then inside
onUnhandledFrame({ frame }):In v3.0.3,
AnyNetworkFrameisNetworkFrame<string, unknown, any>, not a discriminated union, so the protocol comparison doesn't narrowframe.data. The class guard narrows it to the HTTP frame, whose data includesrequest: Request.Sources: export, base type, and MSW's own use of this guard.
This is an …