Skip to content

Commit

Permalink
Use stream_socket_client() exception for better message (#183)
Browse files Browse the repository at this point in the history
* Use stream_socket_client() exception for better message

* catch exception better
  • Loading branch information
rudiedirkx authored Oct 17, 2023
1 parent f08600f commit 3d6c876
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/Downloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Spatie\SslCertificate;

use ErrorException;
use Spatie\SslCertificate\Exceptions\CouldNotDownloadCertificate;
use Spatie\SslCertificate\Exceptions\InvalidIpAddress;

Expand Down Expand Up @@ -180,14 +181,20 @@ protected function fetchCertificates(string $hostName): array
$connectTo = $hostName;
}

$client = @stream_socket_client(
"ssl://{$connectTo}:{$this->port}",
$errorNumber,
$errorDescription,
$this->timeout,
STREAM_CLIENT_CONNECT,
$streamContext
);
try {
$client = stream_socket_client(
"ssl://{$connectTo}:{$this->port}",
$errorNumber,
$errorDescription,
$this->timeout,
STREAM_CLIENT_CONNECT,
$streamContext
);
}
catch (ErrorException $exception) {
$client = null;
$errorDescription = trim(str_replace('stream_socket_client():', '', $exception->getMessage()));
}

if (! empty($errorDescription)) {
throw $this->buildFailureException($connectTo, $errorDescription);
Expand Down

0 comments on commit 3d6c876

Please sign in to comment.