fix(amis): ErrorBoundary细节调整

This commit is contained in:
wibetter 2023-11-22 11:40:45 +08:00
parent 7b7d58c41c
commit 0c233986f5
2 changed files with 8 additions and 10 deletions

View File

@ -6,7 +6,8 @@
import React from 'react';
interface ErrorBoundaryProps {
curErrorSchema?: any;
// 自定义错误信息,控制台输出
customErrorMsg?: string;
fallback?: () => void;
children: any;
}
@ -25,12 +26,9 @@ export default class ErrorBoundary extends React.Component<
}
componentDidCatch(error: any, errorInfo: any) {
const {curErrorSchema} = this.props;
if (curErrorSchema) {
console.warn(
`拦截到${curErrorSchema.type}渲染错误当前组件schema:`,
curErrorSchema
);
const {customErrorMsg} = this.props;
if (customErrorMsg) {
console.warn(customErrorMsg);
}
console.warn('错误对象:', error);
@ -41,7 +39,7 @@ export default class ErrorBoundary extends React.Component<
}
render() {
const {curErrorSchema, fallback} = this.props;
const {fallback} = this.props;
if (this.state.hasError) {
if (fallback) {
return fallback();
@ -50,7 +48,7 @@ export default class ErrorBoundary extends React.Component<
// 默认渲染错误信息
return (
<div className="ae-Editor-renderer-error">
{curErrorSchema.type}
</div>
);
}

View File

@ -135,7 +135,7 @@ export function supportStatic<T extends FormControlProps>() {
return (
<ErrorBoundary
curErrorSchema={props.$schema}
customErrorMsg={`拦截到${props.$schema.type}渲染错误当前组件schema: ${props.$schema}`}
fallback={() => {
return (
<div className="ae-Editor-renderer-error">