mswjs / msw

Industry standard API mocking for JavaScript.
https://mswjs.io
MIT License
15.97k stars 519 forks source link

fix: cannot read properties of undefined (reading 'url') #2239

Closed baegofda closed 2 months ago

baegofda commented 2 months ago

fix error cannot read properties of undefined (reading 'url') (ref. #2193) image This bug is said to be fixed in the latest version, but it's still an issue for some users, including myself (I'm currently using version 2.3.5).

In the createResponseListener function, sometimes const request = context.requests.get(requestId) is possible undefined. so reference error in request.url in the code below.

if (!response.url) {
  Object.defineProperty(response, 'url', {
    value: request.url,
    enumerable: true,
    writable: false,
  })
}

The same issue does not occur when using the changed version with this code.