This commit is contained in:
fuenmao
2026-08-27 16:27:17 +08:00
parent 6d4ad7236f
commit d0d7ca8e69
7 changed files with 150 additions and 48 deletions
+6 -4
View File
@@ -18,8 +18,10 @@ import { ElNotification } from "element-plus";
* @description 全局代码错误捕捉
* */
const errorHandler = (error: any) => {
// 过滤 HTTP 请求错误
if (error.status || error.status == 0) return false;
// 过滤 HTTP 请求错误与接口业务返回错误(这类错误已在 Axios 拦截器中统一通过 ElMessage 弹出提示,无需重复告警)
if (!error || error.status !== undefined || error.code !== undefined || error.isAxiosError || error.config) {
return false;
}
let errorMap: { [key: string]: string } = {
InternalError: "Javascript引擎内部错误",
ReferenceError: "未找到对象",
@@ -29,10 +31,10 @@ const errorHandler = (error: any) => {
EvalError: "错误的使用了Eval",
URIError: "URI错误"
};
let errorName = errorMap[error.name] || "未知错误";
let errorName = errorMap[error?.name] || "未知错误";
ElNotification({
title: errorName,
message: error,
message: error?.message || String(error),
type: "error",
duration: 3000
});