亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

獲取請求中的錯誤不會停止功能

獲取請求中的錯誤不會停止功能

MYYA 2023-10-10 15:19:25
我已經在我的網站上實現了 firebase 登錄,我將信息發送到我的服務器。我在那里創建會話和 csrf 令牌。但我發現如果我的 csrf 不匹配,我會收到錯誤,但該函數會繼續運行,就像登錄成功一樣。這是代碼:postIdTokenToSessionLogin("/sessionLogin", idToken, csrfToken).then(      function() {        // Redirect to profile on success.        console.log("login succesful"); //this gets logged even if "postIdTokenToSessionLogin" gets caught         // window.location.assign("/profile");      },      function(error) {        console.log(error); //i need this to run        window.location.assign("/");      }    );postIdTokenToSessionLogin = async function(url, idToken, csrfToken) {  // POST to session login endpoint.  const data = {    idToken,    _csrf: csrfToken  };  console.log(data);  options = {    method: "POST",    body: JSON.stringify(data),    headers: {      "Content-Type": "application/json"    }  };  // POST to session login endpoint.  return fetch(url, options).catch(err => {     throw err; //---------here i do get the error,   });};我哪里錯了?
查看完整描述

1 回答

?
PIPIONE

TA貢獻1829條經驗 獲得超9個贊

您必須依賴ok以下屬性Response:


fetch('https://httpbin.org/status/500')

.then(res => {

    if (res.ok) {

        return res;

    } else {

        throw res;

    }

}).catch(err => {

    console.error('Error: ', err.status);

});


查看完整回答
反對 回復 2023-10-10
  • 1 回答
  • 0 關注
  • 106 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號