]> jaekl.net Git - frank.git/commitdiff
Add user-friendly explanation for server timeout.
authorChris Jaekl <cejaekl@yahoo.com>
Sun, 28 Dec 2014 20:14:48 +0000 (15:14 -0500)
committerChris Jaekl <cejaekl@yahoo.com>
Sun, 28 Dec 2014 20:14:48 +0000 (15:14 -0500)
WEB-INF/classes/frank.properties
prod/frank.properties
prod/net/jaekl/frank/ErrorHandler.java
prod/net/jaekl/frank/FrankBundle.java
test/net/jaekl/frank/ErrorHandlerTest.java

index 4f35303a61c3ecd4797057d05ae54473a1328d8e..fcfcfbf1e048d3601e61a1b8dd23a228f3ab7a97 100644 (file)
@@ -13,6 +13,7 @@ remain=Remain
 request.made=Request made:
 route=Route
 s=s
+server.timeout=Frank requested information from the OC Transpo server, but it did not respond in a timely manner.  This probably indicates that the OC Transpo server is temporarily unavailable.  It may come back online soon; please try again in a few minutes.
 unexpected.error=Unexpected Error
 unexpected.exception=An unexpected exception has been raised.  This probably indicates a bug in Frank.
 url.contacted=URL contacted:
index 4f35303a61c3ecd4797057d05ae54473a1328d8e..fcfcfbf1e048d3601e61a1b8dd23a228f3ab7a97 100644 (file)
@@ -13,6 +13,7 @@ remain=Remain
 request.made=Request made:
 route=Route
 s=s
+server.timeout=Frank requested information from the OC Transpo server, but it did not respond in a timely manner.  This probably indicates that the OC Transpo server is temporarily unavailable.  It may come back online soon; please try again in a few minutes.
 unexpected.error=Unexpected Error
 unexpected.exception=An unexpected exception has been raised.  This probably indicates a bug in Frank.
 url.contacted=URL contacted:
index c1d72bd8d96bcaa8c3fc35434b66ae707275ee2f..428925a8b5f5616101c9febfcb75ccac42f3229e 100644 (file)
@@ -3,6 +3,7 @@ package net.jaekl.frank;
 import java.io.ByteArrayOutputStream;
 import java.io.PrintStream;
 import java.io.PrintWriter;
+import java.net.SocketTimeoutException;
 import java.util.Locale;
 
 import net.jaekl.qd.http.InvalidResponseException;
@@ -53,6 +54,9 @@ public class ErrorHandler {
                        pw.println("</P>");
                        pw.println("<P>" + bundle.get(FrankBundle.MAYBE_SERVER_PROBLEM) + "</P>");
                }
+               else if (cause instanceof SocketTimeoutException) {
+                       pw.println(bundle.get(FrankBundle.SERVER_TIMEOUT));
+               }
                else {
                        pw.println(bundle.get(FrankBundle.UNEXPECTED_EXCEPTION));
                }
index 8d5057a9092775535e76b4c4de6d279da10c3841..4cac888552c8f878dac2d92da1e2085cf50c0506 100644 (file)
@@ -23,6 +23,7 @@ public class FrankBundle {
        public static final String REQUEST_MADE = "request.made";
        public static final String ROUTE = "route";
        public static final String SECONDS = "s";
+       public static final String SERVER_TIMEOUT = "server.timeout";
        public static final String UNEXPECTED_ERROR = "unexpected.error";
        public static final String UNEXPECTED_EXCEPTION = "unexpected.exception";
        public static final String URL_CONTACTED = "url.contacted";
index 4db0602c8cf428aa4deb7bef90f500ba4fc2da57..235d04fb3277b1984b9bc16c8efcee16340265d2 100644 (file)
@@ -3,6 +3,7 @@ package net.jaekl.frank;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.net.SocketTimeoutException;
 import java.sql.SQLException;
 import java.util.Locale;
 
@@ -56,20 +57,29 @@ public class ErrorHandlerTest {
        }
        
        @Test
-       public void testExplain_unexpectedException() {
+       public void testExplain_simpleExceptions() {
                Locale[] locales = { Locale.CANADA, Locale.FRANCE, Locale.JAPAN, Locale.CHINA};
+               Object[][] data = { 
+                               {new NullPointerException(), FrankBundle.UNEXPECTED_EXCEPTION},
+                               {new SocketTimeoutException(), FrankBundle.SERVER_TIMEOUT}
+                       };
                
                ErrorHandler eh = new ErrorHandler();
                
                for (Locale locale : locales) {
                        FrankBundle bundle = FrankBundle.getInst(locale);
                        
-                       m_baos.reset();
-                       eh.writeErrorPage(m_pw, new NullPointerException(),  Locale.CANADA);
-                       m_pw.flush();
-                       
-                       String actual = m_baos.toString();
-                       Assert.assertTrue(actual.contains(bundle.get(FrankBundle.UNEXPECTED_EXCEPTION)));
+                       for (Object[] tuple : data) {
+                               Exception e = (Exception)tuple[0];
+                               String key = (String)tuple[1];
+                               
+                               m_baos.reset();
+                               eh.writeErrorPage(m_pw, e, locale);
+                               m_pw.flush();
+                               
+                               String actual = m_baos.toString();
+                               Assert.assertTrue(actual.contains(bundle.get(key)));
+                       }
                }
        }