Files
MomoWen 3e2da1115e
Some checks failed
Call HTTPS API / build (push) Has been cancelled
初始化拉取,原文件名:admin-plus-webpack5
2025-12-26 20:43:10 +08:00

31 lines
882 B
TypeScript

import { App } from 'vue'
import pinia from '@/store'
import { useErrorLogStore } from '@/store/modules/errorLog'
import { errorLog } from '@/config'
import { isArray, isString } from '@/utils/validate'
export const needErrorLog = () => {
const errorLogArray = isArray(errorLog)
? [...errorLog]
: isString(errorLog)
? [...[errorLog]]
: []
return errorLogArray.includes(process.env.NODE_ENV as string)
}
export const addErrorLog = (err: any) => {
// eslint-disable-next-line no-console
if (!err.isRequest) console.error('vue-admin-better错误拦截:', err)
const url = window.location.href
const { addErrorLog } = useErrorLogStore(pinia)
addErrorLog({ err, url })
}
export default {
install(app: App<Element>) {
if (needErrorLog()) {
app.config.errorHandler = addErrorLog
}
},
}