Exception 反应并续写错误处理以显示来自前端的消息
我正在使用React with axios向前端发送post请求,一旦发送post请求,就会出现以下错误“Unhandled rejection SequelizeUniqueConstraintError:Validation error”,但在前端没有任何问题。 我如何在前端处理此问题以向用户显示消息Exception 反应并续写错误处理以显示来自前端的消息,exception,react-router,Exception,React Router,我正在使用React with axios向前端发送post请求,一旦发送post请求,就会出现以下错误“Unhandled rejection SequelizeUniqueConstraintError:Validation error”,但在前端没有任何问题。 我如何在前端处理此问题以向用户显示消息 <Button type='submit' variant='contained'
<Button
type='submit'
variant='contained'
color='primary'
size='large'
onClick={() => {
axios
.post(
`http://${config.host}:${config.port}/apartment`,
{
apartment_id: apartment_id,
apartment_block_id: selected_tower,
apartment_block_name:
apartment_data.apartment_block_name,
apartment_floor: apartment_floor,
apartment_size: selected_apartment_data,
apartment_parking_id: selected_apartment_data,
},
)
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
}}
>
Cadastrar
</Button>
{
axios
.邮政(
`http://${config.host}:${config.port}/plant`,
{
公寓id:公寓id,
公寓楼号:选定的楼号,
公寓\街区\名称:
公寓楼数据。公寓楼街区名称,
公寓楼:公寓楼,
公寓大小:选定的公寓数据,
公寓\停车\ id:所选公寓\数据,
},
)
.然后(功能(响应){
控制台日志(响应);
})
.catch(函数(错误){
console.log(错误);
});
}}
>
地籍