Skip to content

Commit

Permalink
Add logging for db execptons handling
Browse files Browse the repository at this point in the history
Signed-off-by: Avgustin Marinov <[email protected]>
  • Loading branch information
avgustinmm committed Dec 19, 2024
1 parent 52fec7c commit f5eb535
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ private static HttpStatus getStatusOrDefault(final SpServerError error) {

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());
}
Expand Down Expand Up @@ -334,5 +334,4 @@ private boolean shouldExclude(final HttpServletRequest request) {
return false;
}
}

}

0 comments on commit f5eb535

Please sign in to comment.