aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2019-04-29 22:31:55 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2019-04-29 22:31:55 -0700
commit238f5d9b8b9e4819a9909a7403dcbc7bec0dc714 (patch)
tree883a7f71551876b5161857d73a9f428b3227f3b1 /src
parent35b902cd59070a7185d99640851b99798a0d1eb7 (diff)
downloadtrackermap-server-238f5d9b8b9e4819a9909a7403dcbc7bec0dc714.tar.gz
trackermap-server-238f5d9b8b9e4819a9909a7403dcbc7bec0dc714.tar.bz2
trackermap-server-238f5d9b8b9e4819a9909a7403dcbc7bec0dc714.zip
Log exception root cause
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/traccar/api/ResourceErrorHandler.java12
-rw-r--r--src/main/java/org/traccar/helper/Log.java5
-rw-r--r--src/test/java/org/traccar/helper/LogTest.java13
3 files changed, 19 insertions, 11 deletions
diff --git a/src/main/java/org/traccar/api/ResourceErrorHandler.java b/src/main/java/org/traccar/api/ResourceErrorHandler.java
index 1d618b08d..108a8e8cc 100644
--- a/src/main/java/org/traccar/api/ResourceErrorHandler.java
+++ b/src/main/java/org/traccar/api/ResourceErrorHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2019 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,14 +26,8 @@ public class ResourceErrorHandler implements ExceptionMapper<Exception> {
@Override
public Response toResponse(Exception e) {
if (e instanceof WebApplicationException) {
- WebApplicationException exception = (WebApplicationException) e;
- String message;
- if (exception.getCause() != null) {
- message = Log.exceptionStack(exception.getCause());
- } else {
- message = Log.exceptionStack(exception);
- }
- return Response.fromResponse(exception.getResponse()).entity(message).build();
+ WebApplicationException webException = (WebApplicationException) e;
+ return Response.fromResponse(webException.getResponse()).entity(Log.exceptionStack(webException)).build();
} else {
return Response.status(Response.Status.BAD_REQUEST).entity(Log.exceptionStack(e)).build();
}
diff --git a/src/main/java/org/traccar/helper/Log.java b/src/main/java/org/traccar/helper/Log.java
index f328e8ce9..607a0585f 100644
--- a/src/main/java/org/traccar/helper/Log.java
+++ b/src/main/java/org/traccar/helper/Log.java
@@ -211,6 +211,11 @@ public final class Log {
}
public static String exceptionStack(Throwable exception) {
+ Throwable cause;
+ while (null != (cause = exception.getCause()) && (exception != cause) ) {
+ exception = cause;
+ }
+
StringBuilder s = new StringBuilder();
String exceptionMsg = exception.getMessage();
if (exceptionMsg != null) {
diff --git a/src/test/java/org/traccar/helper/LogTest.java b/src/test/java/org/traccar/helper/LogTest.java
index 853eb05c9..ef33c32ba 100644
--- a/src/test/java/org/traccar/helper/LogTest.java
+++ b/src/test/java/org/traccar/helper/LogTest.java
@@ -7,8 +7,17 @@ import static org.junit.Assert.assertEquals;
public class LogTest {
@Test
- public void testLog() {
- assertEquals("test - Exception (LogTest:11 < ...)", Log.exceptionStack(new Exception("test")));
+ public void testExceptionStack() {
+ assertEquals(
+ "test - Exception (LogTest:11 < ...)",
+ Log.exceptionStack(new Exception("test")));
+ }
+
+ @Test
+ public void testExceptionStackRootCause() {
+ assertEquals(
+ "root - Exception (LogTest:18 < ...)",
+ Log.exceptionStack(new Exception("test", new Exception("root"))));
}
}