feat: 日志优化
This commit is contained in:
11
src/App.js
11
src/App.js
@@ -50,6 +50,7 @@ import ProtectedRoute from "components/ProtectedRoute";
|
||||
import ErrorBoundary from "components/ErrorBoundary";
|
||||
import AuthModalManager from "components/Auth/AuthModalManager";
|
||||
import ScrollToTop from "components/ScrollToTop";
|
||||
import { logger } from "utils/logger";
|
||||
|
||||
function AppContent() {
|
||||
const { colorMode } = useColorMode();
|
||||
@@ -172,13 +173,19 @@ export default function App() {
|
||||
// 全局错误处理:捕获未处理的 Promise rejection
|
||||
useEffect(() => {
|
||||
const handleUnhandledRejection = (event) => {
|
||||
console.error('未捕获的 Promise rejection:', event.reason);
|
||||
logger.error('App', 'unhandledRejection', event.reason instanceof Error ? event.reason : new Error(String(event.reason)), {
|
||||
promise: event.promise
|
||||
});
|
||||
// 阻止默认的错误处理(防止崩溃)
|
||||
event.preventDefault();
|
||||
};
|
||||
|
||||
const handleError = (event) => {
|
||||
console.error('全局错误:', event.error);
|
||||
logger.error('App', 'globalError', event.error || new Error(event.message), {
|
||||
filename: event.filename,
|
||||
lineno: event.lineno,
|
||||
colno: event.colno
|
||||
});
|
||||
// 阻止默认的错误处理(防止崩溃)
|
||||
event.preventDefault();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user