feat: 接通后台渲染异常上报与响应契约校验
This commit is contained in:
1 parent
330d67adc1
commit
adcaa12970
22 files changed
+845
-33
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import { Component, type ErrorInfo, type ReactNode } from "react";
|
||||
import { Button, Result, Space, Typography } from "antd";
|
||||
import { createApiClient } from "../lib/api.js";
|
||||
|
||||
interface AdminErrorBoundaryProps {
|
||||
children: ReactNode;
|
||||
@@ -24,13 +25,28 @@ export class AdminErrorBoundary extends Component<
|
||||
AdminErrorBoundaryState
|
||||
> {
|
||||
override state: AdminErrorBoundaryState = { error: null, errorId: null };
|
||||
private reportedErrorId: string | null = null;
|
||||
|
||||
static getDerivedStateFromError(error: Error): AdminErrorBoundaryState {
|
||||
return { error, errorId: createErrorId() };
|
||||
}
|
||||
|
||||
override componentDidCatch(error: Error, info: ErrorInfo) {
|
||||
console.error("[admin] 页面渲染异常", this.state.errorId, error, info.componentStack);
|
||||
const errorId = this.state.errorId ?? createErrorId();
|
||||
console.error("[admin] 页面渲染异常", errorId, error, info.componentStack);
|
||||
if (this.reportedErrorId === errorId) return;
|
||||
this.reportedErrorId = errorId;
|
||||
// 上报失败不能影响错误页本身:只记录到控制台,不抛出、不改状态。
|
||||
void createApiClient()
|
||||
.reportAdminClientError({
|
||||
errorId,
|
||||
message: error.message.slice(0, 2000) || error.name,
|
||||
route: `${window.location.pathname}${window.location.search}`.slice(0, 500),
|
||||
...(info.componentStack ? { componentStack: info.componentStack.slice(0, 20000) } : {}),
|
||||
})
|
||||
.catch((reportError: unknown) => {
|
||||
console.warn("[admin] 渲染异常上报失败", errorId, reportError);
|
||||
});
|
||||
}
|
||||
|
||||
private reset = () => {
|
||||
|
||||
Reference in new issue
Block a user