File tree Expand file tree Collapse file tree
main/java/io/github/adeniyikayodee/ngpostcode/api
test/java/io/github/adeniyikayodee/ngpostcode/api Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -146,7 +146,13 @@ private static String encode(String text) {
146146 }
147147
148148 private static <T > Result <T > failed (Throwable error ) {
149- String reason = error .getMessage () != null ? error .getMessage () : error .getClass ().getSimpleName ();
149+ String reason = error .getMessage ();
150+ if (reason == null ) {
151+ // The JDK gives a failed connection no message: its cause says which kind.
152+ Throwable cause = error .getCause ();
153+ reason = error .getClass ().getSimpleName ()
154+ + (cause != null ? ": " + cause .getClass ().getSimpleName () : "" );
155+ }
150156 return new Result .Failed <>(new TransportError (reason ));
151157 }
152158}
Original file line number Diff line number Diff line change @@ -170,4 +170,12 @@ void aSilentServerTimesOutAsAValueWithoutTheKey() throws IOException {
170170 assertInstanceOf (TransportError .class , nowhere .failure ());
171171 }
172172 }
173+
174+ @ Test
175+ void aRefusedConnectionSaysWhatFailed () throws IOException {
176+ Client client = clientFor (exchange -> {});
177+ server .stop (0 );
178+ var failed = assertInstanceOf (Result .Failed .class , client .send (Api .lookup (CODE )));
179+ assertTrue (failed .failure ().toString ().matches ("ConnectException: \\ w+" ), failed .failure ().toString ());
180+ }
173181}
You can’t perform that action at this time.
0 commit comments