Iceberry-qdd / icehub-frontend

A twitter-like social networking site.
MIT License
0 stars 0 forks source link

🐛 接口异常处理中catch语句的变量e的含义模糊不清 #55

Closed Iceberry-qdd closed 1 month ago

Iceberry-qdd commented 6 months ago

如下代码:

https://github.com/Iceberry-qdd/icehub-frontend/blob/a37f32e334744f52071fdac2845c6d2b69a3045d/src/components/bootstrap/Explore.vue#L56-L65

以下两种代码,哪一种是正确的呢? e代表的是后端返回的error对象才对吧,而不是error对象中的error属性?

Iceberry-qdd commented 2 months ago

目前正在修复,报错时,将不会打印日志,具体变更如下:

[修改前]

try {
    const response = await fetchSth()
    if (!response.ok) throw new Error((await response.json()).error)
    ...
} catch(e) {
    store.setErrorMsg(e.message)
    console.error(e)
}

[修改后]

try {
    const response = await fetchSth()
    if (!response.ok) throw new Error((await response.json()).error)
    ...
} catch(e) {
    store.setErrorMsg(e.message)
}