Skip to content

Commit

Permalink
Changed AsyncHttpConnector to specify more base exception types and f…
Browse files Browse the repository at this point in the history
…ewer specialized types.

In particular, we catch HttpException to also catch Http2ConnectionException.
Some permanent HTTP exceptions, most notably those caused by invalid
configuration, are specified as exclusions.
  • Loading branch information
Bilge committed Jul 16, 2021
1 parent c49fe63 commit 0c1cc56
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/AsyncHttpConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
use Amp\Http\Client\Cookie\InMemoryCookieJar;
use Amp\Http\Client\HttpClient;
use Amp\Http\Client\HttpClientBuilder;
use Amp\Http\Client\HttpException;
use Amp\Http\Client\Interceptor\TooManyRedirectsException;
use Amp\Http\Client\InvalidRequestException;
use Amp\Http\Client\ParseException;
use Amp\Http\Client\Request;
use Amp\Http\Client\Response;
use Amp\Http\Client\SocketException;
Expand Down Expand Up @@ -57,10 +61,15 @@ public function fetchAsync(AsyncDataSource $source): Promise
/** @var Response $response */
$response = yield $client->request($this->createRequest($source));
$body = yield $response->getBody()->buffer();
// Retry HTTP timeouts, socket timeouts, DNS resolution, TLS negotiation and connection reset errors.
} catch (TimeoutException|SocketException|DnsException|TlsException|StreamException
|UnprocessedRequestException $exception) {
// Convert exception to recoverable exception.
} catch (TooManyRedirectsException|InvalidRequestException|ParseException $exception) {
// Exclude permanent exceptions that subclass HttpException.
throw $exception;
} catch (DnsException|StreamException|HttpException $exception) {
/*
* Retry intermittent DNS failures, low-level stream errors including TLS negotiation failures
* and all manner of HTTP exceptions including, but not limited to, socket timeouts and connection
* resets by converting them to a recoverable exception type.
*/
throw new HttpConnectionException($exception->getMessage(), $exception->getCode(), $exception);
}

Expand Down

0 comments on commit 0c1cc56

Please sign in to comment.