improves error message for InvocationTargetExceptions

Fri, 22 May 2020 17:19:09 +0200

author
Mike Becker <universe@uap-core.de>
date
Fri, 22 May 2020 17:19:09 +0200
changeset 73
672b5003cafe
parent 72
0646c14e36fb
child 74
91d1fc2a3a14

improves error message for InvocationTargetExceptions

src/main/java/de/uapcore/lightpit/AbstractLightPITServlet.java file | annotate | diff | comparison | revisions
--- a/src/main/java/de/uapcore/lightpit/AbstractLightPITServlet.java	Fri May 22 16:21:59 2020 +0200
+++ b/src/main/java/de/uapcore/lightpit/AbstractLightPITServlet.java	Fri May 22 17:19:09 2020 +0200
@@ -40,6 +40,7 @@
 import javax.servlet.http.HttpSession;
 import java.io.IOException;
 import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.sql.Connection;
@@ -132,10 +133,17 @@
                 }
             }
             return (ResponseType) method.invoke(this, paramValues);
+        } catch (InvocationTargetException ex) {
+            LOG.error("invocation of method {}::{} failed: {}",
+                    method.getDeclaringClass().getName(), method.getName(), ex.getTargetException().getMessage());
+            LOG.debug("Details: ", ex.getTargetException());
+            resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ex.getTargetException().getMessage());
+            return ResponseType.NONE;
         } catch (ReflectiveOperationException | ClassCastException ex) {
-            LOG.error("invocation of method {} failed: {}", method.getName(), ex.getMessage());
+            LOG.error("invocation of method {}::{} failed: {}",
+                    method.getDeclaringClass().getName(), method.getName(), ex.getMessage());
             LOG.debug("Details: ", ex);
-            resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+            resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ex.getMessage());
             return ResponseType.NONE;
         }
     }

mercurial