diff --git a/src/errorHandling.js b/src/errorHandling.js index 6126b8fc..e0d0940d 100644 --- a/src/errorHandling.js +++ b/src/errorHandling.js @@ -22,3 +22,33 @@ export function handleError(shouldLog, error, more = {}) { // Do something cool } + +export function getErrorHandled(func) { + return async function errorHandled(...args) { + try { + return await func(...args); + } catch (error) { + handleError(false, error, { + functionName: func.name, + functionArgs: args, + }); + + throw error; + } + }; +} + +export function getErrorHandledSync(func) { + return function errorHandledSync(...args) { + try { + return func(...args); + } catch (error) { + handleError(false, error, { + functionName: func.name, + functionArgs: args, + }); + + throw error; + } + }; +} diff --git a/src/main.js b/src/main.js index 807d785d..88d653bf 100644 --- a/src/main.js +++ b/src/main.js @@ -4,7 +4,7 @@ import Vue from 'vue'; import models from '../models'; import App from './App'; import FeatherIcon from './components/FeatherIcon'; -import { handleError } from './errorHandling'; +import { getErrorHandled, handleError } from './errorHandling'; import { IPC_MESSAGES } from './messages'; import router from './router'; import { outsideClickDirective } from './ui'; @@ -16,6 +16,9 @@ import { stringifyCircular } from './utils'; frappe.initializeAndRegister(models); frappe.fetch = window.fetch.bind(); + ipcRenderer.send = getErrorHandled(ipcRenderer.send); + ipcRenderer.invoke = getErrorHandled(ipcRenderer.invoke); + frappe.events.on('reload-main-window', () => { ipcRenderer.send(IPC_MESSAGES.RELOAD_MAIN_WINDOW); });