Skip to content
Discussion options

You must be logged in to vote

HttpNetworkFrame is exported from msw/experimental. You can use frame instanceof HttpNetworkFrame instead of checking frame.protocol === 'http'.

Import it with:

import { HttpNetworkFrame } from 'msw/experimental'

Then inside onUnhandledFrame({ frame }):

if (frame instanceof HttpNetworkFrame) {
  const { request } = frame.data
  console.log('Unhandled %s %s', request.method, request.url)
}

In v3.0.3, AnyNetworkFrame is NetworkFrame<string, unknown, any>, not a discriminated union, so the protocol comparison doesn't narrow frame.data. The class guard narrows it to the HTTP frame, whose data includes request: Request.

Sources: export, base type, and MSW's own use of this guard.

This is an …

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@kettanaito
Comment options

@kettanaito
Comment options

Answer selected by Semigradsky
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants