From 65ef31e702929cb2b2c24335377a225d2f137076 Mon Sep 17 00:00:00 2001 From: Avgustin Marinov Date: Thu, 19 Dec 2024 16:37:57 +0200 Subject: [PATCH] Add logging for db execptons handling (#2155) Signed-off-by: Avgustin Marinov --- .../jpa/aspects/ExceptionMappingAspectHandler.java | 10 ++++++++-- .../org/eclipse/hawkbit/rest/RestConfiguration.java | 3 +-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/aspects/ExceptionMappingAspectHandler.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/aspects/ExceptionMappingAspectHandler.java index b28126569..72c91153d 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/aspects/ExceptionMappingAspectHandler.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/aspects/ExceptionMappingAspectHandler.java @@ -71,9 +71,15 @@ public class ExceptionMappingAspectHandler implements Ordered { // It is a AspectJ proxy which deals with exceptions. @SuppressWarnings({ "squid:S00112", "squid:S1162" }) public void catchAndWrapJpaExceptionsService(final Exception ex) throws Throwable { + if (log.isTraceEnabled()) { + log.trace("Handling exception {}", ex.getClass().getName(), ex); + } else { + log.debug("Handling exception {}", ex.getClass().getName()); + } + // Workaround for EclipseLink merge where it does not throw ConstraintViolationException directly in case of existing entity update - if (ex instanceof TransactionSystemException) { - throw replaceWithCauseIfConstraintViolationException((TransactionSystemException) ex); + if (ex instanceof TransactionSystemException transactionSystemException) { + throw replaceWithCauseIfConstraintViolationException(transactionSystemException); } for (final Class mappedEx : MAPPED_EXCEPTION_ORDER) { diff --git a/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/RestConfiguration.java b/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/RestConfiguration.java index 7ec646dd0..7f9c70a8e 100644 --- a/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/RestConfiguration.java +++ b/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/RestConfiguration.java @@ -279,7 +279,7 @@ public class RestConfiguration { private void logRequest(final HttpServletRequest request, final Exception ex) { if (log.isTraceEnabled()) { - log.debug("Handling exception {} of request {}", ex.getClass().getName(), request.getRequestURL(), ex); + log.trace("Handling exception {} of request {}", ex.getClass().getName(), request.getRequestURL(), ex); } else { log.debug("Handling exception {} of request {}", ex.getClass().getName(), request.getRequestURL()); } @@ -334,5 +334,4 @@ public class RestConfiguration { return false; } } - } \ No newline at end of file