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/06/10 15:06:45 UTC

[unomi] branch master updated: UNOMI-488 : log error in RuntimeExceptionMapper (#311)

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

dgriffon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/unomi.git


The following commit(s) were added to refs/heads/master by this push:
     new d8e5cb1  UNOMI-488 : log error in RuntimeExceptionMapper (#311)
d8e5cb1 is described below

commit d8e5cb15453116003dbf622a9bf1c45326a91b19
Author: David Griffon <dg...@jahia.com>
AuthorDate: Thu Jun 10 17:06:38 2021 +0200

    UNOMI-488 : log error in RuntimeExceptionMapper (#311)
---
 .../apache/unomi/rest/exception/RuntimeExceptionMapper.java | 13 ++++++++++++-
 1 file changed, 12 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..00ee3dc 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,7 +16,10 @@
  */
 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;
@@ -28,11 +31,19 @@ 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
+}