fetch icon indicating copy to clipboard operation
fetch copied to clipboard

response.clone() still throwing this stream has already been locked

Open alvaroraminelli opened this issue 2 years ago • 0 comments
trafficstars

Hello Team,

Looks like response.clone() does not work as expected when trying to re-read the response.

const myRequest = new Request('https://restcountries.com/v3.1/region/europe');

fetch(myRequest)
  .then((response) => {
    const response2 = response.clone();

    response.json().then((myRes) => {
      console.log('Response', myRes);
    });

    response2
      .json()
      .then((myRes) => {
        console.log('Response2 --->', myRes);
      })
      .catch((e) => {
        console.log('@@@@@@');
        console.log(e);
        console.log('@@@@@@');
      });
  });
@@@@@@
[TypeError: This stream has already been locked for exclusive reading by another reader]
@@@@@@```

alvaroraminelli avatar Jun 02 '23 23:06 alvaroraminelli