我在另一个文件上执行了相同的catch错误,并且可以工作,但在这个文件上失败了。我唯一的不同是添加了两个参数,知道吗?
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);
});
});