From 57675010604a8b2df81b6c0ebf72d8a37bc57e7e Mon Sep 17 00:00:00 2001 From: Shrikant Sharat Kandula Date: Wed, 3 Apr 2024 13:08:29 +0530 Subject: [PATCH] chore: Refactor API for hiding logs (#32358) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sorry for quickly changing the signature(s) of this. 1. The generic method in the super class just wasn't working well. The generic return type needs to be set explicitly in some places, and is inferred in some, and is just too volatile. So we replicate the method definition in both the subclasses for better API usage code. 2. The field already has a getter with Lombok, I didn't need to write a new one. 🤦 --- .../appsmith/external/exceptions/BaseException.java | 12 +----------- .../pluginExceptions/AppsmithPluginException.java | 5 +++++ .../server/exceptions/AppsmithException.java | 5 +++++ .../server/exceptions/GlobalExceptionHandler.java | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/exceptions/BaseException.java b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/exceptions/BaseException.java index d344b31f6e..92fbe857b2 100644 --- a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/exceptions/BaseException.java +++ b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/exceptions/BaseException.java @@ -11,7 +11,7 @@ public abstract class BaseException extends RuntimeException { private Map contextMap; - private boolean hideStackTraceInLogs = false; + protected boolean hideStackTraceInLogs = false; public BaseException(String message) { super(message); @@ -38,14 +38,4 @@ public abstract class BaseException extends RuntimeException { public abstract String getDownstreamErrorCode(); public abstract String getErrorType(); - - @SuppressWarnings("unchecked") - public T hideStackTraceInLogs() { - hideStackTraceInLogs = true; - return (T) this; - } - - public boolean shouldHideStackTraceInLogs() { - return hideStackTraceInLogs; - } } diff --git a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/exceptions/pluginExceptions/AppsmithPluginException.java b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/exceptions/pluginExceptions/AppsmithPluginException.java index c4d564f3c7..0d2989df2f 100644 --- a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/exceptions/pluginExceptions/AppsmithPluginException.java +++ b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/exceptions/pluginExceptions/AppsmithPluginException.java @@ -60,4 +60,9 @@ public class AppsmithPluginException extends BaseException { ? AppsmithPluginErrorCode.GENERIC_PLUGIN_ERROR.getCode() : this.error.getAppErrorCode(); } + + public AppsmithPluginException hideStackTraceInLogs() { + hideStackTraceInLogs = true; + return this; + } } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/AppsmithException.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/AppsmithException.java index fcd26ffe40..195c891a3f 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/AppsmithException.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/AppsmithException.java @@ -63,4 +63,9 @@ public class AppsmithException extends BaseException { public String getReferenceDoc() { return this.error.getReferenceDoc(); } + + public AppsmithException hideStackTraceInLogs() { + hideStackTraceInLogs = true; + return this; + } } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/GlobalExceptionHandler.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/GlobalExceptionHandler.java index e421a5d1e5..e261121174 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/GlobalExceptionHandler.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/GlobalExceptionHandler.java @@ -67,7 +67,7 @@ public class GlobalExceptionHandler { } private void doLog(Throwable error) { - if (error instanceof BaseException baseException && baseException.shouldHideStackTraceInLogs()) { + if (error instanceof BaseException baseException && baseException.isHideStackTraceInLogs()) { log.error(baseException.getClass().getSimpleName() + ": " + baseException.getMessage()); } else { log.error("", error);