Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,13 @@ private static String encode(String text) {
}

private static <T> Result<T> failed(Throwable error) {
String reason = error.getMessage() != null ? error.getMessage() : error.getClass().getSimpleName();
String reason = error.getMessage();
if (reason == null) {
// The JDK gives a failed connection no message: its cause says which kind.
Throwable cause = error.getCause();
reason = error.getClass().getSimpleName()
+ (cause != null ? ": " + cause.getClass().getSimpleName() : "");
}
return new Result.Failed<>(new TransportError(reason));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,12 @@ void aSilentServerTimesOutAsAValueWithoutTheKey() throws IOException {
assertInstanceOf(TransportError.class, nowhere.failure());
}
}

@Test
void aRefusedConnectionSaysWhatFailed() throws IOException {
Client client = clientFor(exchange -> {});
server.stop(0);
var failed = assertInstanceOf(Result.Failed.class, client.send(Api.lookup(CODE)));
assertTrue(failed.failure().toString().matches("ConnectException: \\w+"), failed.failure().toString());
}
}
Loading