【发布时间】:2018-07-31 09:59:53
【问题描述】:
我收到 “UnhandledPromiseRejectionWarning: Unhandled Promise Rejection.” 错误,我无法执行上述简单请求:
app.get('/', function (req, res) {
const GITHUB_AUTH_ACCESSTOKEN_URL = 'https://github.com/login/oauth/access_token'
const CLIENT_ID = '123'
const CLIENT_SECRET = '456'
axios({
method: 'post',
url: GITHUB_AUTH_ACCESSTOKEN_URL,
data: {
client_id: CLIENT_ID,
client_secret: CLIENT_SECRET
}
})
.then(function (response) {
alert('Sucess ' + JSON.stringify(response))
})
.catch(function (error) {
alert('Error ' + JSON.stringify(error))
})
});
我不明白为什么会发生这种情况,因为我正在使用“.catch()”方法正确处理错误。如何正确执行此请求?
【问题讨论】:
标签: javascript node.js http axios