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

前端 未结 10 1956
南旧
南旧 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:45

    There is a new option called validateStatus in request config. You can use it to specify to not throw exceptions if status < 100 or status > 300 (default behavior). Example:

    const {status} = axios.get('foo.com', {validateStatus: () => true})
    

提交回复
热议问题