How can I get the status code from an http error in Axios?

前端 未结 10 1943
南旧
南旧 2020-11-28 02:27

This may seem stupid, but I\'m trying to get the error data when a request fails in Axios.

axios.get(\'foo.com\')
    .then((response) => {})
    .catch((         


        
10条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-28 02:47

    You can put the error into an object and log the object, like this:

    axios.get('foo.com')
        .then((response) => {})
        .catch((error) => {
            console.log({error}) // this will log an empty object with an error property
        });
    

    Hope this help someone out there.

提交回复
热议问题