async/await - 4.处理async函数中的错误
const fetch = require('node-fetch')
async function getZhihuColumn(id) {
const url = `https:`
const response = await fetch(url)
if (response.status !== 200) {
throw new Error(response.status.statusText)
}
return await response.json()
}
const showColumnInfo = async (id) => {
try {
const creator = await getZhihuColumn(id)
console.log(`name:${creator.name}`)
console.log(`description:${creator.description}`)
} catch (err) {
console.error(err)
}
}
showColumnInfo('qianduanzhidian111')