【发布时间】:2021-05-13 16:34:26
【问题描述】:
发送 axios put 请求并获取状态码 400 错误。
在 catch 块中,我希望收到带有 error.message 的消息,但这等于 Request failed with status code 400
try {
dispatch({
type: SETTINGS_ALERT,
})
const response = await axios.put(
`/author/me`,
{
data: {
DisplayName: displayName,
Description: description,
},
}
)
dispatch({
type: SETTINGS_UPDATE_PROFILE_SUCCESS,
payload: response.data,
})
} catch (error) {
//need to handle it here, bu error.message not works
dispatch({
type: SETTINGS_LOAD_FAIL,
error: error.message,
})
}
我怎样才能正确阅读这条消息??
【问题讨论】:
-
先尝试使用
console.log(String(error)。看看会发生什么。 -
我认为 error.response.data 是你要找的