Catch Error Unhandled Предупреждение об отклонении обещания - PullRequest
0 голосов
/ 27 ноября 2018

Я сделал ту же ошибку перехвата для другого файла, и она работает, но не удалось на этом.Единственное отличие, которое я сделал, - это добавление двух параметров, вы понимаете?

app.get('/getearth', (req, res) => {
  const lat = req.query.lat;
  const lon = req.query.lon;
  const date = req.query.date;
  const querystr = `https://api.nasa.gov/planetary/earth/imagery?lon=${lon}&lat=${lat}&date=${date}&cloud_score=True&api_key=${apikey}`;

  axios
    .get(querystr)
    .then(response => {
      const earth = new Earth({
        cloud_score: response.data.cloud_score,
        date: response.data.date,
        url: response.data.url
      });
      if (!earth.date || !earth.lon || !earth.lat) {
        res.status(200).json('Not found');
        return;
      }
      earth
        .save()
        .then(response => {
          res.status(200).json(response);
        })
        .catch(error => {
          res.status(400).json(error);
        });
    })
    .catch(error => {
      res.status(400).json(error);
    });
});
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...