From bf5272f3fc7e8f893f16198290230bc297772bea Mon Sep 17 00:00:00 2001
From: Chris Jaekl
" + bundle.get(FrankBundle.MAYBE_SERVER_PROBLEM) + "
"); } + else if (cause instanceof SocketTimeoutException) { + pw.println(bundle.get(FrankBundle.SERVER_TIMEOUT)); + } else { pw.println(bundle.get(FrankBundle.UNEXPECTED_EXCEPTION)); } diff --git a/prod/net/jaekl/frank/FrankBundle.java b/prod/net/jaekl/frank/FrankBundle.java index 8d5057a..4cac888 100644 --- a/prod/net/jaekl/frank/FrankBundle.java +++ b/prod/net/jaekl/frank/FrankBundle.java @@ -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"; diff --git a/test/net/jaekl/frank/ErrorHandlerTest.java b/test/net/jaekl/frank/ErrorHandlerTest.java index 4db0602..235d04f 100644 --- a/test/net/jaekl/frank/ErrorHandlerTest.java +++ b/test/net/jaekl/frank/ErrorHandlerTest.java @@ -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))); + } } } -- 2.39.2