2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

axiosでエラー情報を取得

Posted at

##概要
axiosでAPI通信を行い、APIの方でエラーが発生した場合のエラー情報の取得方法についてまとめていきたい。

#####catchで取得したエラーの中身をみていく

axios

axios.get('https://example.com', params)
.then(function(response) {

    //正常時にAPIから返却されるレスポンスデータ
    return response;
  })
  .catch(function(error) {
    
    //エラー時にAPIから返却されるレスポンスデータ
    error.response.data();
  });

キャッチしたHTTPステータスコードをフロント側で処理することも可能そうです。

2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?