const onSubmit = async () => {
showError(false)
try {
await axios.post("http://localhost:9005/api/Users", user);
// history.push("/")
handleClose()
props.snackbarShowMessage(`User Added Successfully `)
data()
formReset()
} catch(error) {
showError(true)
console.log('asdfg',error)
props.snackbarShowError(error.response.data.error[0].msg)
}
};
将响应分配给变量,然后检查其响应状态。 您可以使用...来验证这一点
const x = await axios.post("http://localhost:9005/api/Users", user);
console.log(x.statusCode);
请注意,try catch 将处理反应错误而不是 axios 错误..