Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert SocketException to guzzle ConnectException #3

Open
wants to merge 1 commit into
base: 1.x
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion src/GuzzleHandlerAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Amp\Http\Client\Psr7\PsrHttpClientException;
use Amp\Http\Client\Request as AmpRequest;
use Amp\Http\Client\Response;
use Amp\Http\Client\SocketException;
use Amp\Http\Tunnel\Http1TunnelConnector;
use Amp\Http\Tunnel\Https1TunnelConnector;
use Amp\Socket\Certificate;
Expand All @@ -25,6 +26,7 @@
use Amp\Socket\SocketConnector;
use Amp\Socket\Socks5SocketConnector;
use AssertionError;
use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\Promise\Promise;
use GuzzleHttp\Promise\PromiseInterface;
use GuzzleHttp\Psr7\Request as GuzzleRequest;
Expand Down Expand Up @@ -121,7 +123,7 @@ public function __invoke(PsrRequest $request, array $options): PromiseInterface

/** @psalm-suppress UndefinedVariable Using $promise reference in definition expression. */
$promise = new Promise(
function () use (&$promise, $future, $cancellation, $deferredCancellation): void {
function () use (&$promise, $future, $cancellation, $deferredCancellation, $request): void {
if ($deferredCancellation->isCancelled()) {
return;
}
Expand All @@ -138,6 +140,8 @@ function () use (&$promise, $future, $cancellation, $deferredCancellation): void
if (!$cancellation->isRequested()) {
$promise->reject($e);
}
} catch (SocketException $e) {
$promise->reject(new ConnectException($e->getMessage(), $request, $e));
} catch (\Throwable $e) {
$promise->reject($e);
}
Expand Down
Loading