// 上报错误(及时上报)
import {apiReportingErrInfo} from '@/api/common'

const reportErr=(app)=>{
    let errObj={}
    app.config.errorHandler=(err, instance, info)=>{
        console.error(err)
        errObj={
            msg:err.message,
            stack:err.stack,
            userAgent:window.navigator.userAgent
        }
        if(import.meta.env.MODE==='production'){
            apiReportingErrInfo({errInfo:errObj})
        }
    }

    window.addEventListener('error',(e)=>{
        console.error(e)
        errObj={
            msg:e.error?.message,
            stack:e.error?.stack,
            userAgent:window.navigator.userAgent
        }
        if(import.meta.env.MODE==='production'){
            apiReportingErrInfo({errInfo:errObj})
        }
    })
}



export default reportErr