📜  fetch catch - 任何代码示例

📅  最后修改于: 2022-03-11 14:56:48.354000             🧑  作者: Mango

代码示例5
fetch(url).then((response) => {
  if (response.ok) {
    return response.json();
  } else {
    throw new Error('Something went wrong');
  }
})
.then((responseJson) => {
  // Do something with the response
})
.catch((error) => {
  console.log(error)
});