Skip to content

Commit 04810a0

Browse files
committed
Prettier "Can't connect" message in response
1 parent 20563d0 commit 04810a0

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

lib/LWP/Protocol/http.pm

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,14 @@ sub _new_socket
4040

4141
unless ($sock) {
4242
# IO::Socket::INET leaves additional error messages in $@
43-
$@ =~ s/^.*?: //;
44-
die "Can't connect to $host:$port ($@)";
43+
my $status = "Can't connect to $host:$port";
44+
if ($@ =~ /\bconnect: (.*)/ ||
45+
$@ =~ /\b(Bad hostname)\b/ ||
46+
$@ =~ /\b(certificate verify failed)\b/
47+
) {
48+
$status .= " ($1)";
49+
}
50+
die "$status\n\n$@";
4551
}
4652

4753
# perl 5.005's IO::Socket does not have the blocking method.

0 commit comments

Comments
 (0)