From c3c72470dca628a7a5afe52ac1e009168b78f0a5 Mon Sep 17 00:00:00 2001 From: 18alantom <2.alan.tom@gmail.com> Date: Wed, 19 Jan 2022 16:43:50 +0530 Subject: [PATCH] feat: action only if autoReport is not active --- src/errorHandling.js | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/errorHandling.js b/src/errorHandling.js index 377f8b1f..6aff9a2b 100644 --- a/src/errorHandling.js +++ b/src/errorHandling.js @@ -15,6 +15,24 @@ function reportError(errorLogObj) { console.log(errorLogObj); } +function getToastProps(errorLogObj) { + const props = { + message: _(`Error: `) + errorLogObj.name, + type: 'error', + }; + + if (!frappe.SystemSettings.autoReportErrors) { + Object.assign(props, { + actionText: frappe._('Report Error'), + action: () => { + reportError(errorLogObj); + }, + }); + } + + return props; +} + export function handleError(shouldLog, error, more = {}) { if (shouldLog) { console.error(error); @@ -26,17 +44,13 @@ export function handleError(shouldLog, error, more = {}) { const { name, stack, message } = error; const errorLogObj = { name, stack, message, more }; + frappe.errorLog.push(errorLogObj); - // Do something cool - showToast({ - message: _(`Error: `) + name, - actionText: frappe._('Report Error'), - type: 'error', - action: () => { - reportError(errorLogObj); - }, - }); + showToast(getToastProps(errorLogObj)); + if (frappe.SystemSettings.autoReportErrors) { + reportError(errorLogObj); + } } export function getErrorMessage(e, doc) {