1 回答

TA貢獻1891條經驗 獲得超3個贊
根據 axios處理錯誤,底層錯誤數據message
應在以下位置提供error.response.data
:
.catch((error) => {
? token = null
? console.log('error =>', error.response.data)
});
您可能想要使用該示例并處理可能發生的不同類型的錯誤:
.catch(function (error) {
? if (error.response) {
? ? // The request was made and the server responded with a status code
? ? // that falls out of the range of 2xx
? ? console.log(error.response.data);
? ? console.log(error.response.status);
? ? console.log(error.response.headers);
? } else if (error.request) {
? ? // The request was made but no response was received
? ? // `error.request` is an instance of XMLHttpRequest in the browser and an instance of
? ? // http.ClientRequest in node.js
? ? console.log(error.request);
? } else {
? ? // Something happened in setting up the request that triggered an Error
? ? console.log('Error', error.message);
? }
? ? console.log(error.config);
});
希望這有幫助!
添加回答
舉報