response.json() throws “TypeError: Failed to fetch”

I use fetch for getting some resources from the server. I can see from logs that from time to time conversion to JSON fails on "TypeError: Failed to fetch" which is very interesting because should only happen when the request fails.

The simplified code I use:

const response = await fetch('https:/something.com/api')
await response.json() // -> throws TypeError: Failed to fetch

I cannot really find the case when it might happen. I tested possible cases and all failed on the first line of code, i.e. fetch('https:/something.com/api'). I have no idea when this might happen. I also should mention that it happens in modern browsers like chrome 99. So it is not definitely something like internet explorer thing.

Cases tested:

  1. Network error – user disconnected from the internet
  2. CORS – missing CORS headers