Javascript 如何在vue typescript中处理异步/等待错误

Javascript 如何在vue typescript中处理异步/等待错误,javascript,typescript,vue.js,async-await,Javascript,Typescript,Vue.js,Async Await,代码片段是 async getInfo(): Promise<any>{ let response; try{ response = await Axios.get('api/***') //response.json() //what is json here? //Error here is "[ts] Property 'j

代码片段是

    async getInfo(): Promise<any>{
    let response;
    try{
        response = await Axios.get('api/***')
        //response.json()  
                        //what is json here?
                        //Error here is "[ts] Property 'json' does not exist on type 'AxiosResponse<any>'."      
    }catch(err){
        response = err;
        console.log(err)
    }
    return response;
}
async getInfo():承诺{
让我们回应;
试一试{
response=wait Axios.get('api/***')
//response.json()
//这里是什么?
//此处的错误是“[ts]属性“json”在类型“AxiosResponse”上不存在。”
}捕捉(错误){
响应=错误;
console.log(错误)
}
返回响应;
}
在这里,err不能作为json打印,我如何将其转换为json?它是这样显示的
错误:请求失败,状态代码403

您不需要执行
response.json()
,响应本身应该是一个json对象。通过console.log(response)@Helpinghand进行检查,他的问题不是响应打印,而是错误对象打印为jsonyeah,以纠正@Helpinghand,它只是一个JSON,为什么这个错误不是JSON?我做错了什么?@Sam err是AxiosError的一个实例,该对象有一个名为
response
的属性。然后,您可以将
err
转换为json对象:
response=err.response |{error:err.error}刚刚看到这个并解决了我的问题,这就是你的回答,谢谢。