LoginSignup
0
0

More than 3 years have passed since last update.

1つ目のAPIが通った場合のみ次のAPIを実行するエラーハンドリング

Posted at

1つ目のAPIを実行してうまく通った場合にのみ、
次のAPIを実行するような処理を実装する一例。

※下記のサンプルではVuex、Axiosで実装しています

index.js
async getData({ commit, state }) {
  try {
    await this.$axios.
      $get('URI')
      .then(() => {
        this.$axios
          .$get('URI')
          .then((resp) => {
            commit('setData', resp)
          })
          .catch((error) => {
            console.log(error)
          })
      } catch((error) => {
        console.log(error)
      })
    } catch (error) {
      console.log(error) [
    }
  }
}

Actiosの中での実装を想定しているので、
commitでMutationsにある(想定)setDataにデータを渡しています。

0
0
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
0
0