2
0
mirror of https://github.com/frappe/books.git synced 2024-11-10 07:40:55 +00:00

feat: error handle ipcRenderer.[send, invoke]

This commit is contained in:
18alantom 2022-01-19 11:44:12 +05:30 committed by Alan
parent 7b61eec372
commit f8c76603d2
2 changed files with 34 additions and 1 deletions

View File

@ -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;
}
};
}

View File

@ -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);
});