Improve error reporting. New error page that gives a bit more of an explanation...
[frank.git] / prod / net / jaekl / frank / ViewSchedule.java
index e044f70ba21fa8a47cdaccad421a9384a5ccc856..b13258b3a8ce66227652ee6880886823601528ce 100644 (file)
@@ -1,9 +1,7 @@
 package net.jaekl.frank;
 
-import java.io.ByteArrayOutputStream;
 import java.io.FileInputStream;
 import java.io.IOException;
-import java.io.PrintStream;
 import java.io.PrintWriter;
 import java.util.Locale;
 
@@ -24,6 +22,12 @@ public class ViewSchedule extends HttpServlet {
        static final String ROUTE = "route";
        static final String LANG = "lang";
        
+       ErrorHandler m_errorHandler;
+       
+       public ViewSchedule() {
+               m_errorHandler = new ErrorHandler();
+       }
+       
        int getParamInt(HttpServletRequest req, String paramName) {
                String valueStr = getParamString(req, paramName);
                try {
@@ -88,38 +92,7 @@ public class ViewSchedule extends HttpServlet {
                        }
                }
                catch (Throwable t) {
-                       writeErrorPage(pw, t, locale);
+                       m_errorHandler.writeErrorPage(pw, t, locale);
                }
        }
-       
-       void writeErrorPage(PrintWriter pw, Throwable t, Locale locale) {
-               ByteArrayOutputStream baos = new ByteArrayOutputStream();
-               PrintStream ps = new PrintStream(baos);
-               FrankBundle bundle = FrankBundle.getInst(locale);
-               
-               pw.println("<HTML><HEAD><TITLE>" + 
-                               bundle.get(FrankBundle.FRANK) + ": " +
-                               bundle.get(FrankBundle.ERROR_PAGE) + 
-                               "</TITLE></HEAD>");
-               pw.println("<BODY><H1>" +
-                               bundle.get(FrankBundle.FRANK) + ": " +
-                               bundle.get(FrankBundle.UNEXPECTED_ERROR) + 
-                               "</H1><P><PRE>");
-
-               // Note that, if we cared about security, we would log this stack trace to a
-               // server log, and only report a cross-reference to the log file back to the 
-               // end user's browser, to avoid potentially exposing internal info that we 
-               // don't want to share.
-               // At least at this point, we don't care (that much), and trade off a 
-               // potential information leak in favour of reducing our code complexity
-               // and the administrator's workload.
-               t.printStackTrace(ps);
-               String stackTrace = baos.toString(); 
-               pw.println(stackTrace);
-                               
-               pw.println("</PRE></P></BODY>");
-               pw.println("</HTML>");
-       }
-       
-
 }