第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

使用 axioson 400 和 401 狀態(tài)代碼檢索響應(yīng)錯(cuò)誤

使用 axioson 400 和 401 狀態(tài)代碼檢索響應(yīng)錯(cuò)誤

楊魅力 2023-08-18 14:20:35
我正在嘗試使用 axios 進(jìn)行身份驗(yàn)證,但何時(shí)出現(xiàn)錯(cuò)誤 400 或 401,在電子郵件和密碼丟失或錯(cuò)誤的情況下,我無(wú)法從 API 獲取響應(yīng)消息,控制臺(tái)記錄 axios 錯(cuò)誤僅向我顯示以下內(nèi)容:錯(cuò)誤=>錯(cuò)誤:在XMLHttpRequest.handleLoad(1.chunk.js:103940)處的createError(1.chunk.js:104463)處的解決(1.chunk.js:104697)處請(qǐng)求失敗,狀態(tài)代碼為400不知道如何獲得正確的回復(fù),如下:{“errors”:[{“message”:“請(qǐng)?zhí)峁╇娮余]件和密碼?!眪]}這是我的代碼(...)axios.post('some api for authentication',        {            email: formData.email,            password: formData.password,            remember: formData.remember        })        .then(response => {          token = response.data.session.user          console.log('response =>', token)        })        .catch((error) => {          token = null          console.log('error =>', error)        })(...)
查看完整描述

1 回答

?
萬(wàn)千封印

TA貢獻(xiàn)1891條經(jīng)驗(yàn) 獲得超3個(gè)贊

根據(jù) axios處理錯(cuò)誤,底層錯(cuò)誤數(shù)據(jù)message應(yīng)在以下位置提供error.response.data

.catch((error) => {

? token = null

? console.log('error =>', error.response.data)

});

您可能想要使用該示例并處理可能發(fā)生的不同類(lèi)型的錯(cuò)誤:


.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);

});

希望這有幫助!


查看完整回答
反對(duì) 回復(fù) 2023-08-18
  • 1 回答
  • 0 關(guān)注
  • 186 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)