Javascript 当后端API应用程序未运行时,如何处理Vue JS应用程序?

Javascript 当后端API应用程序未运行时,如何处理Vue JS应用程序?,javascript,vue.js,error-handling,Javascript,Vue.js,Error Handling,当后端api应用程序不工作或未启动时,将在浏览器控制台中收到以下错误 OPTIONS http://127.0.0.1:3000/api/user_token net::ERR_CONNECTION_REFUSED 如何处理这个错误 axios.get(url, oprtions) .then((response) => console.log(response)) .catch((error) => console.log(error)); // error.respon

当后端api应用程序不工作或未启动时,将在浏览器控制台中收到以下错误

OPTIONS http://127.0.0.1:3000/api/user_token net::ERR_CONNECTION_REFUSED
如何处理这个错误

axios.get(url, oprtions)
  .then((response) => console.log(response))
  .catch((error) => console.log(error)); // error.response, error.response.status, and so on

阅读有关错误处理的更多信息:


感谢您的回复,如果(!error.response){alert(“Server not response”);return;},我可以通过以下代码捕获错误来处理它,但我需要将此放在每个API请求中,这不是一个好的做法,我们应该如何通过将此代码放在一个位置来处理?
fetch(url, oprtions)
  .then((response) => console.log(response))
  .catch((error) => console.log(error)); // error.response, error.response.status, and so on