fix(miniprogram): 添加全局 ErrorBoundary,修复 tryRefreshToken 静默吞异常

This commit is contained in:
iven
2026-04-24 12:20:34 +08:00
parent f3716dbdc5
commit 74d7efec1f
3 changed files with 42 additions and 3 deletions

View File

@@ -0,0 +1,38 @@
import React, { Component } from 'react';
import { View, Text } from '@tarojs/components';
interface Props {
children: React.ReactNode;
}
interface State {
hasError: boolean;
}
export default class ErrorBoundary extends Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = { hasError: false };
}
static getDerivedStateFromError(): State {
return { hasError: true };
}
componentDidCatch(error: Error, info: React.ErrorInfo) {
console.error('[ErrorBoundary]', error, info.componentStack);
}
render() {
if (this.state.hasError) {
return (
<View style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', minHeight: '60vh', padding: '40px' }}>
<Text style={{ fontSize: '48px', marginBottom: '20px' }}>😵</Text>
<Text style={{ fontSize: '32px', color: '#134E4A', marginBottom: '12px' }}></Text>
<Text style={{ fontSize: '24px', color: '#94A3B8', marginBottom: '24px' }}></Text>
</View>
);
}
return this.props.children;
}
}