async 捕捉错误

  • try…catch

  • 返回的数据正确的和错误合并到一起处理

    const fn = async() => {
    	let res&&err = await fetchFn().then(res => res).catch(err => err)
    }
    
  • 返回的数据正确的和错误的分开处理

    const fn = async() =>{
    	let [err,res] = await fetchFn().then(res =>[null,res].catch(err => [err,null]))
    }
    
posted @ 2022-06-08 15:47  Mmonologue  阅读(57)  评论(0)    收藏  举报