React-admin 如何显示有关服务器错误的通知

React-admin how show notification about error from server

反应管理员:2.9.5

我有下一个密码

const CreateUserComponentBase = (props) => {
    const { ...rest } = props

    return (
        <SimpleForm
            validate={validate}
            {...rest}
        >
            {/*...code*/}
        </SimpleForm>
    )
}

const UserCreateBase = (props: any) => {
    const { setTitle, ...rest } = props

    return (
        <Create {...rest}>
            <CreateUserForm {...rest}  isEdit={false} />
        </Create>
    )
};

我在服务器上发送请求,我的 API 生成一条错误消息,如果 React-Admin 仅显示“服务器错误”,我该如何输出此消息

我不知道 v2.9.5,但在最新版本中,您可以像这样使用 onSuccessonFailure 回调

const handleFailure = (error) => {
  notify(`Something bad happened: ${error}`), 'error');
};

const handleSuccess = (data) => {
  notify('Success!');
  redirect('show', props.basePath, data.id);
  refresh();
};

return (
  <Edit
    {...props}
    onFailure={handleFailure}
    onSuccess={handleSuccess}
  >
    ...
  </Edit>
);