Skip to content

Commit

Permalink
Improved renderer error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Jun 21, 2022
1 parent 8ce8ffe commit 56d8cb3
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 23 deletions.
38 changes: 35 additions & 3 deletions app/codes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ const fs = require("fs")
/**
* Send error to main process
*/
window.onerror = (error) => {
ipc.send("rendererError", { renderer: "application", error })
}
window.addEventListener("error", (err) => {
ipc.invoke("rendererError", { renderer: "codes", error: err.error.stack })
})

/**
* Start logger
Expand Down Expand Up @@ -328,6 +328,38 @@ const generateCodeElements = (data) => {
}
}, 500)

if (settings.settings.search_filter) {
const http = require("http")

/**
* Handle requests
* @type {http.RequestListener}
*/
const requestListener = (req, res) => {
const headers = {
"Access-Control-Allow-Origin": "*",
}

const key = "asd"
const url = req.url
const param = req.url.split("apiKey=")[1]

if (url.startsWith("/codes") && param === key) {
res.writeHead(200, headers)
res.end(JSON.stringify({ names, secrets, issuers }))
} else {
res.writeHead(403, headers)
res.end(JSON.stringify({ message: "403 - Access denied" }))
}
}

const server = http.createServer(requestListener)

server.listen(1010, () => {
console.log("Server started")
})
}

// latest search from history
const latest_search = settings.search_history.latest

Expand Down
6 changes: 3 additions & 3 deletions app/confirm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ const fs = require("fs")
/**
* Send error to main process
*/
window.onerror = (error) => {
ipc.send("rendererError", { renderer: "confirm", error })
}
window.addEventListener("error", (err) => {
ipc.invoke("rendererError", { renderer: "confirm", error: err.error.stack })
})

/**
* Start logger
Expand Down
6 changes: 3 additions & 3 deletions app/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ const fs = require("fs")
/**
* Send error to main process
*/
window.onerror = (error) => {
ipc.send("rendererError", { renderer: "edit", error })
}
window.addEventListener("error", (err) => {
ipc.invoke("rendererError", { renderer: "edit", error: err.error.stack })
})

/**
* Start logger
Expand Down
6 changes: 3 additions & 3 deletions app/export/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ const fs = require("fs")
/**
* Send error to main process
*/
window.onerror = (error) => {
ipc.send("rendererError", { renderer: "export", error })
}
window.addEventListener("error", (err) => {
ipc.invoke("rendererError", { renderer: "export", error: err.error.stack })
})

/**
* Start logger
Expand Down
6 changes: 3 additions & 3 deletions app/import/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ const { useWebcam } = require("./functions/webcam")
/**
* Send error to main process
*/
window.onerror = (error) => {
ipc.send("rendererError", { renderer: "import", error })
}
window.addEventListener("error", (err) => {
ipc.invoke("rendererError", { renderer: "import", error: err.error.stack })
})

/**
* Start logger
Expand Down
6 changes: 3 additions & 3 deletions app/landing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ const fs = require("fs")
/**
* Send error to main process
*/
window.onerror = (error) => {
ipc.send("rendererError", { renderer: "landing", error })
}
window.addEventListener("error", (err) => {
ipc.invoke("rendererError", { renderer: "landing", error: err.error.stack })
})

/**
* Start logger
Expand Down
6 changes: 3 additions & 3 deletions app/settings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ const fs = require("fs")
/**
* Send error to main process
*/
window.onerror = (error) => {
ipc.send("rendererError", { renderer: "settings", error })
}
window.addEventListener("error", (err) => {
ipc.invoke("rendererError", { renderer: "settings", error: err.error.stack })
})

/**
* Start logger
Expand Down
5 changes: 3 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ process.on("uncaughtException", async (error) => {
build: number,
os: `${os.type()} ${os.arch()} ${os.release()}`,
stack: stack.clean(error.stack),
lang: app.getLocaleCountryCode(),
date: new Date(),
})
} catch (error) {
Expand Down Expand Up @@ -107,7 +108,7 @@ const folder_path = dev ? path.join(app.getPath("appData"), "Levminer", "Authme

// Check if /Levminer path exists
if (!fs.existsSync(full_path)) {
fs.mkdirSync(path.join(full_path))
fs.mkdirSync(full_path)
}

// Check if /Authme path exists
Expand Down Expand Up @@ -1336,7 +1337,7 @@ ipc.on("reloadExportWindow", () => {
/**
* Receive error from renderer
*/
ipc.on("rendererError", async (event, data) => {
ipc.handle("rendererError", async (event, data) => {
logger.error(`Error in ${data.renderer}`, data.error)

if (dev === false) {
Expand Down

0 comments on commit 56d8cb3

Please sign in to comment.