1057010
我用 util.promisify() 包装了 https.get() 方法, 按文档上说的可以这样写
const { promisify } = require('util')
const https = require('https')
const get = promisify(https.get)
// get.catch = () => {}
async function httpsGet(url) {
const res = await get(url)
// res.catch(() => {})
console.log(res)
}
httpsGet('https://baidu.com')
然而会这样
但是, then 写法就能得到结果
get('https://baidu.com')
.then(res => {
console.log(res.data)
})
.catch(err => {
console.log(err)
})
这是为何? node v8.1.2