我正在尝试 console.log 天气 API 的一些数据,但是当我查找位置时收到错误消息
UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 4)
到目前为止,我的代码在我的服务器上是这样的
app.post('/weather', (req, res) => {
const url = `https://api.darksky.net/forecast/${DARKSKY_API_KEY}/${req.body.latitude},${req.body.longitude}?units=auto`
axios({
url: url,
responseType: 'json'
}).then(data => res.json(data.data.currently)).catch(error => { throw error})
})
app.listen(3000, () => {
console.log("Server has started")
})
Run Code Online (Sandbox Code Playgroud)
和我的 JavaScript
fetch('/weather', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': …Run Code Online (Sandbox Code Playgroud)