[Mulgara-svn] r1404 - in trunk/src/jar: util/java/org/mulgara/util web/java/org/mulgara/webquery
pag at mulgara.org
pag at mulgara.org
Fri Dec 5 23:51:59 UTC 2008
Author: pag
Date: 2008-12-05 15:51:58 -0800 (Fri, 05 Dec 2008)
New Revision: 1404
Modified:
trunk/src/jar/util/java/org/mulgara/util/StackTrace.java
trunk/src/jar/web/java/org/mulgara/webquery/QueryServlet.java
Log:
Better error reporting for users
Modified: trunk/src/jar/util/java/org/mulgara/util/StackTrace.java
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/StackTrace.java 2008-12-05 23:50:30 UTC (rev 1403)
+++ trunk/src/jar/util/java/org/mulgara/util/StackTrace.java 2008-12-05 23:51:58 UTC (rev 1404)
@@ -108,4 +108,24 @@
t.printStackTrace(new PrintWriter(strWriter));
return strWriter.toString();
}
+
+ /**
+ * Gets the base of the cause chain.
+ * @param t The Throwable to get the cause from.
+ * @return The base of the cause chain for the throwable.
+ */
+ public static Throwable getReason(Throwable t) {
+ while (t.getCause() != null) t = t.getCause();
+ return t;
+ }
+
+ /**
+ * Gets the message from the base cause for a Throwable.
+ * @param t The throwable to get the base of the cause chain for.
+ * @return The message from the base case.
+ */
+ public static String getReasonMessage(Throwable t) {
+ return getReason(t).getMessage();
+ }
+
}
Modified: trunk/src/jar/web/java/org/mulgara/webquery/QueryServlet.java
===================================================================
--- trunk/src/jar/web/java/org/mulgara/webquery/QueryServlet.java 2008-12-05 23:50:30 UTC (rev 1403)
+++ trunk/src/jar/web/java/org/mulgara/webquery/QueryServlet.java 2008-12-05 23:51:58 UTC (rev 1404)
@@ -230,11 +230,14 @@
} catch (MulgaraParserException mpe) {
resp.sendError(SC_BAD_REQUEST, "Error parsing command: " + mpe.getMessage());
return;
+ } catch (RequestException re) {
+ resp.sendError(SC_BAD_REQUEST, "Error processing request: " + re.getMessage());
+ return;
} catch (IllegalStateException ise) {
resp.sendError(SC_SERVICE_UNAVAILABLE, ise.getMessage());
return;
} catch (Exception e) {
- resp.sendError(SC_BAD_REQUEST, "Error executing command: " + StackTrace.throwableToString(e));
+ resp.sendError(SC_BAD_REQUEST, "Error executing command. Reason: " + StackTrace.getReasonMessage(e));
return;
}
More information about the Mulgara-svn
mailing list