Skip to content

Commit b2968ca

Browse files
committed
fix
1 parent ea582af commit b2968ca

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

instrumentation/ratpack/ratpack-1.4/testing/src/main/java/io/opentelemetry/instrumentation/ratpack/client/AbstractRatpackHttpClientTest.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest;
1616
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult;
1717
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions;
18+
import java.net.ConnectException;
1819
import java.net.URI;
1920
import java.nio.channels.ClosedChannelException;
2021
import java.time.Duration;
@@ -179,7 +180,7 @@ private static Throwable nettyClientSpanErrorMapper(URI uri, Throwable exception
179180
if (rootCause instanceof ClosedChannelException) {
180181
return new PrematureChannelClosureException();
181182
}
182-
return rootCause;
183+
return buildConnectTimeoutException(uri, rootCause);
183184
}
184185
return exception;
185186
}
@@ -215,4 +216,20 @@ private static Throwable unwrapConnectionException(Throwable exception) {
215216
}
216217
return current;
217218
}
219+
220+
private static Throwable buildConnectTimeoutException(URI uri, Throwable original) {
221+
String message = "connection timed out: /" + uri.getHost() + ":" + resolvePort(uri);
222+
ConnectException connectException = new ConnectException(message);
223+
if (original != null && original != connectException) {
224+
connectException.initCause(original);
225+
}
226+
return connectException;
227+
}
228+
229+
private static int resolvePort(URI uri) {
230+
if (uri.getPort() != -1) {
231+
return uri.getPort();
232+
}
233+
return uri.getScheme().equalsIgnoreCase("https") ? 443 : 80;
234+
}
218235
}

0 commit comments

Comments
 (0)