LoginSignup
12
14

More than 3 years have passed since last update.

axiosでネットワークエラー・タイムアウトエラーをハンドルする

Last updated at Posted at 2019-08-01

axiosでネットワークエラー・タイムアウトエラーをハンドルする場合、以下のように判定可能です。

axios.interceptors.response.use(
  function(error) {
      //タイムアウトの場合
      const isTimeout = error.code === "ECONNABORTED";
      if (isTimeout) {
        //do something
        return;
      }

      //ネットワークエラーの場合
      if (!error.response) {
        //do something
        return;
      }
  }
);
12
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
14