mirror of
https://github.com/frappe/books.git
synced 2024-12-23 03:19:01 +00:00
fix: improve error handling
- exit on `uncaughtException` - set `window.onerror` - handle error in contactMothership.js
This commit is contained in:
parent
d324998197
commit
517a0cc6d8
@ -67,6 +67,9 @@ function post(bodyJson) {
|
||||
}
|
||||
);
|
||||
|
||||
req.on('error', (e) => {
|
||||
console.log(`ERROR: ${e.message}`);
|
||||
});
|
||||
req.write(bodyJson);
|
||||
req.end();
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ function shouldNotStore(error: Error) {
|
||||
);
|
||||
}
|
||||
|
||||
async function reportError(errorLogObj: ErrorLog) {
|
||||
async function reportError(errorLogObj: ErrorLog, cb?: Function) {
|
||||
if (!errorLogObj.stack) {
|
||||
return;
|
||||
}
|
||||
@ -34,10 +34,11 @@ async function reportError(errorLogObj: ErrorLog) {
|
||||
stack: errorLogObj.stack,
|
||||
more: JSON.stringify(errorLogObj.more ?? {}),
|
||||
};
|
||||
ipcRenderer.invoke(IPC_ACTIONS.SEND_ERROR, JSON.stringify(body));
|
||||
await ipcRenderer.invoke(IPC_ACTIONS.SEND_ERROR, JSON.stringify(body));
|
||||
cb?.();
|
||||
}
|
||||
|
||||
function getToastProps(errorLogObj: ErrorLog) {
|
||||
function getToastProps(errorLogObj: ErrorLog, cb?: Function) {
|
||||
const props = {
|
||||
message: t`Error: ` + errorLogObj.name,
|
||||
type: 'error',
|
||||
@ -48,8 +49,8 @@ function getToastProps(errorLogObj: ErrorLog) {
|
||||
Object.assign(props, {
|
||||
actionText: t`Report Error`,
|
||||
action: () => {
|
||||
reportError(errorLogObj);
|
||||
reportIssue(errorLogObj);
|
||||
reportError(errorLogObj, cb);
|
||||
},
|
||||
});
|
||||
}
|
||||
@ -60,7 +61,8 @@ function getToastProps(errorLogObj: ErrorLog) {
|
||||
export function handleError(
|
||||
shouldLog: boolean,
|
||||
error: Error,
|
||||
more: object = {}
|
||||
more: object = {},
|
||||
cb?: Function
|
||||
) {
|
||||
if (shouldLog) {
|
||||
console.error(error);
|
||||
@ -78,9 +80,9 @@ export function handleError(
|
||||
|
||||
// @ts-ignore
|
||||
if (frappe.SystemSettings?.autoReportErrors) {
|
||||
reportError(errorLogObj);
|
||||
reportError(errorLogObj, cb);
|
||||
} else {
|
||||
showToast(getToastProps(errorLogObj));
|
||||
showToast(getToastProps(errorLogObj, cb));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,10 +74,19 @@ import { stringifyCircular } from './utils';
|
||||
console.error(err, vm, info);
|
||||
};
|
||||
|
||||
window.onerror = (message, source, lineno, colno, error) => {
|
||||
error = error ?? new Error('triggered in window.onerror');
|
||||
handleError(true, error, { message, source, lineno, colno });
|
||||
};
|
||||
|
||||
process.on('unhandledRejection', (error) => {
|
||||
handleError(true, error);
|
||||
});
|
||||
|
||||
process.on('uncaughtException', (error) => {
|
||||
handleError(true, error, () => process.exit(1));
|
||||
});
|
||||
|
||||
/* eslint-disable no-new */
|
||||
new Vue({
|
||||
el: '#app',
|
||||
|
Loading…
Reference in New Issue
Block a user