import { requestAppStackUpload } from "@/api/app"
import globalConfig from '@/config/global.config.js'
import { useAppStore } from "@/store/useAppStore"
import { useUserStore } from "@/store/useUserStore"

export const setupErrorHandler = (app) => {
	app.config.errorHandler = (err, instance, info) => {
		const appStore = useAppStore()
		const userStore = useUserStore()
		
		requestAppStackUpload({
			appId: globalConfig.appId,
			appPackageName: appStore.packageName,
			deviceNumber: appStore.deviceId,
			data: JSON.stringify(err),
			userId: userStore.userInfo.id
		})
		console.log('error', err)
	}
}