Update error handling in main.ts and globalApi.ts
This commit is contained in:
17
src/main.ts
17
src/main.ts
@@ -5,6 +5,23 @@ import { loadData } from "./ts/storage/globalApi";
|
|||||||
import { initHotkey } from "./ts/hotkey";
|
import { initHotkey } from "./ts/hotkey";
|
||||||
import { polyfill } from "./ts/polyfill";
|
import { polyfill } from "./ts/polyfill";
|
||||||
|
|
||||||
|
const errorHandler = (event: ErrorEvent) => {
|
||||||
|
console.error(event.error)
|
||||||
|
alert(event.error)
|
||||||
|
}
|
||||||
|
const rejectHandler = (event: PromiseRejectionEvent) => {
|
||||||
|
console.error(event.reason)
|
||||||
|
alert(event.reason)
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener('error', errorHandler)
|
||||||
|
window.addEventListener('unhandledrejection', rejectHandler)
|
||||||
|
|
||||||
|
export const removeDefaultHandler = () => {
|
||||||
|
window.removeEventListener('error', errorHandler)
|
||||||
|
window.removeEventListener('unhandledrejection', rejectHandler)
|
||||||
|
}
|
||||||
|
|
||||||
let app: App;
|
let app: App;
|
||||||
try {
|
try {
|
||||||
polyfill()
|
polyfill()
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import { listen } from '@tauri-apps/api/event'
|
|||||||
import { registerPlugin } from '@capacitor/core';
|
import { registerPlugin } from '@capacitor/core';
|
||||||
import { language } from "src/lang";
|
import { language } from "src/lang";
|
||||||
import { startObserveDom } from "../observer";
|
import { startObserveDom } from "../observer";
|
||||||
|
import { removeDefaultHandler } from "src/main";
|
||||||
|
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
export const isTauri = !!window.__TAURI__
|
export const isTauri = !!window.__TAURI__
|
||||||
@@ -504,6 +505,7 @@ export async function loadData() {
|
|||||||
updateTextTheme()
|
updateTextTheme()
|
||||||
updateAnimationSpeed()
|
updateAnimationSpeed()
|
||||||
updateHeightMode()
|
updateHeightMode()
|
||||||
|
updateErrorHandling()
|
||||||
if(db.botSettingAtStart){
|
if(db.botSettingAtStart){
|
||||||
botMakerMode.set(true)
|
botMakerMode.set(true)
|
||||||
}
|
}
|
||||||
@@ -526,6 +528,20 @@ export async function getFetchData(id:string) {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateErrorHandling(){
|
||||||
|
removeDefaultHandler()
|
||||||
|
const errorHandler = (event: ErrorEvent) => {
|
||||||
|
console.error(event.error)
|
||||||
|
alertError(event.error)
|
||||||
|
}
|
||||||
|
const rejectHandler = (event: PromiseRejectionEvent) => {
|
||||||
|
console.error(event.reason)
|
||||||
|
alertError(event.reason)
|
||||||
|
}
|
||||||
|
window.addEventListener('error', errorHandler)
|
||||||
|
window.addEventListener('unhandledrejection', rejectHandler)
|
||||||
|
}
|
||||||
|
|
||||||
const knownHostes = ["localhost","127.0.0.1","0.0.0.0"]
|
const knownHostes = ["localhost","127.0.0.1","0.0.0.0"]
|
||||||
|
|
||||||
interface GlobalFetchArgs {
|
interface GlobalFetchArgs {
|
||||||
|
|||||||
Reference in New Issue
Block a user