You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by dg...@apache.org on 2021/05/27 21:15:26 UTC

[unomi] branch add-log-to-runtimeexceptionmapper created (now 2355408)

This is an automated email from the ASF dual-hosted git repository.

dgriffon pushed a change to branch add-log-to-runtimeexceptionmapper
in repository https://gitbox.apache.org/repos/asf/unomi.git.


      at 2355408  UNOMI-488 : log error in RuntimeExceptionMapper

This branch includes the following new commits:

     new 2355408  UNOMI-488 : log error in RuntimeExceptionMapper

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[unomi] 01/01: UNOMI-488 : log error in RuntimeExceptionMapper

Posted by dg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

dgriffon pushed a commit to branch add-log-to-runtimeexceptionmapper
in repository https://gitbox.apache.org/repos/asf/unomi.git

commit 235540892959bb3a877d86e2583c4ea9df86f969
Author: David Griffon <dg...@jahia.com>
AuthorDate: Thu May 27 23:15:04 2021 +0200

    UNOMI-488 : log error in RuntimeExceptionMapper
---
 .../unomi/rest/exception/RuntimeExceptionMapper.java      | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/rest/src/main/java/org/apache/unomi/rest/exception/RuntimeExceptionMapper.java b/rest/src/main/java/org/apache/unomi/rest/exception/RuntimeExceptionMapper.java
index 9bdce40..128da8d 100644
--- a/rest/src/main/java/org/apache/unomi/rest/exception/RuntimeExceptionMapper.java
+++ b/rest/src/main/java/org/apache/unomi/rest/exception/RuntimeExceptionMapper.java
@@ -16,23 +16,36 @@
  */
 package org.apache.unomi.rest.exception;
 
+import org.apache.commons.lang.ArrayUtils;
 import org.osgi.service.component.annotations.Component;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.ext.ExceptionMapper;
 import javax.ws.rs.ext.Provider;
 
+import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashMap;
 
 @Provider
 @Component(service=ExceptionMapper.class)
 public class RuntimeExceptionMapper implements ExceptionMapper<RuntimeException> {
+    private static final Logger logger = LoggerFactory.getLogger(RuntimeExceptionMapper.class.getName());
 
     @Override
     public Response toResponse(RuntimeException exception) {
         HashMap<String, Object> body = new HashMap<>();
         body.put("errorMessage", "internalServerError");
+        logger.error(
+                "Internal server error {}: {} in {} (Set RuntimeExceptionMapper in debug to get the full stacktrace)",
+                exception.getMessage(),
+                exception,
+                ArrayUtils.isEmpty(exception.getStackTrace()) ? "Stack not available" : exception.getStackTrace()[0]
+        );
+        logger.debug("{}", exception.getMessage(), exception);
         return Response.status(Response.Status.INTERNAL_SERVER_ERROR).header("Content-Type", MediaType.APPLICATION_JSON).entity(body).build();
     }
-}
\ No newline at end of file
+}