0
try {

     fetch(url)
          .then(res => res.json())
          .then(data => {
             console.log(data);
          });
 } 
  catch (e) {
     console.log(e);
  }

所以有时我会ECONNRESET从中得到错误,我希望以某种方式忽略它。

4

1 回答 1

0

尝试以下操作:

fetch(url)
  .then(
    function(response) {
      if (response.status !== 200) {
        console.log('Looks like there was a problem. Status Code: ' +
          response.status);
        return;
      }

      // Examine the text in the response
      response.json().then(function(data) {
        console.log(data);
      });
    }
  )
  .catch(function(err) {
    console.log('Fetch Error :-S', err);
  });

ECONNRESET如果这还不够,请在与检查状态相同的地方检查

于 2019-02-01T21:09:09.477 回答