在Axios.Promise之后设置req.body

时间:2018-10-08 19:27:47

标签: javascript node.js promise axios

我已经坚持了几天,我知道有一个简单的答案,而我却忽略了它。 Console.log是同步的,我可以从Google的Distance API获取返回值,但是当我尝试设置req.body [“ OTHER nRow1”] =时,我得到了一个无法准备好的属性toString,未定义(在pdftk中, pdffiller npm))。因此,我认为我仍在兑现承诺。如何将req.body设置为axios get的结果?我已经走了兔子洞,我已经尝试了一切。谢谢。

        fetchDistance = async function(DISTANCE, req) {
          return axios
            .get(DISTANCE)
            .then(response => {
              console.log();
              const miles = response.data.rows[0].elements[0].distance.text
                .replace("mi", "")
                .trim();
              return miles;
            })
            .catch(function(error) {
              console.log(error);
            })
            .then(result => {
              console.log("toLoc: " + result);
              req["OTHER nRow1"] = result;
              return result;
            });
        };
        var AirportMiles;
        fetchDistance(DISTANCE, req.body)
          .then(function(result) {
            console.log(DISTANCE + "DISTANCE!!!");
            console.log(result + "RESULT!!!");
            console.log((req.body["OTHER nRow1"] = result));
            return result;
          })
          .catch(error => {
            console.log(error);
          })
          .then(data => {
            console.log(data + "DATA!!!!!");
            getData(data);
            return (req.body["OTHER nRow1"] = data);
          });
        console.log("REQ: " + req.body["OTHER nRow1"]);
        req.body["Text13"] = perdiem[0].mileage.MileageCost;
      }
      var mi;
      const getData = data => {
        mi = toInt(data);
      };
      req.body["OTHER nRow1"] = mi;
      // Mileage to Form END

0 个答案:

没有答案