|
8 | 8 | * For the full copyright and license information, please read the LICENSE
|
9 | 9 | * file that was distributed with this source code.
|
10 | 10 | */
|
11 |
| - |
12 | 11 | namespace Http\Adapter;
|
13 | 12 |
|
14 | 13 | use GuzzleHttp\Client;
|
@@ -46,37 +45,46 @@ public function sendRequest(RequestInterface $request)
|
46 | 45 | {
|
47 | 46 | try {
|
48 | 47 | return $this->client->send($request);
|
49 |
| - } catch (Guzzle\RequestException $e) { |
50 |
| - throw $this->handleRequestException($e); |
51 |
| - } catch (Guzzle\GuzzleException $e) { |
52 |
| - // Assert: $e instance of SeekException or TransferException |
| 48 | + } catch (Guzzle\SeekException $e) { |
53 | 49 | throw new RequestException($e->getMessage(), $request, $e);
|
| 50 | + } catch (Guzzle\TransferException $e) { |
| 51 | + throw $this->handleTransferException($e); |
54 | 52 | }
|
55 | 53 | }
|
56 | 54 |
|
57 | 55 | /**
|
58 | 56 | * Converts a Guzzle exception into an Httplug exception.
|
59 | 57 | *
|
60 |
| - * @param Guzzle\RequestException $exception |
| 58 | + * @param Guzzle\TransferException $exception |
61 | 59 | *
|
62 | 60 | * @return RequestException
|
63 | 61 | */
|
64 |
| - private function handleRequestException(Guzzle\RequestException $exception) |
| 62 | + private function handleTransferException(Guzzle\TransferException $exception) |
65 | 63 | {
|
66 |
| - if ($exception instanceof Guzzle\ConnectException || $exception instanceof Guzzle\TooManyRedirectsException) { |
| 64 | + if ($exception instanceof Guzzle\ConnectException) { |
67 | 65 | return new NetworkException($exception->getMessage(), $exception->getRequest(), $exception);
|
68 | 66 | }
|
69 | 67 |
|
70 |
| - // Make sure we have a response for the HttpException |
71 |
| - if ($exception->hasResponse()) { |
72 |
| - return new HttpException( |
73 |
| - $exception->getMessage(), |
74 |
| - $exception->getRequest(), |
75 |
| - $exception->getResponse(), |
76 |
| - $exception |
77 |
| - ); |
| 68 | + if ($exception instanceof Guzzle\RequestException) { |
| 69 | + // Make sure we have a response for the HttpException |
| 70 | + if ($exception->hasResponse()) { |
| 71 | + return new HttpException( |
| 72 | + $exception->getMessage(), |
| 73 | + $exception->getRequest(), |
| 74 | + $exception->getResponse(), |
| 75 | + $exception |
| 76 | + ); |
| 77 | + } |
| 78 | + |
| 79 | + if ($exception instanceof Guzzle\TooManyRedirectsException) { |
| 80 | + // Do not convert TooManyRedirectsException |
| 81 | + return $exception; |
| 82 | + //return new HttpException($exception->getMessage(), $exception->getRequest(), null, $exception); |
| 83 | + } |
| 84 | + |
| 85 | + return new RequestException($exception->getMessage(), $exception->getRequest(), $exception); |
78 | 86 | }
|
79 | 87 |
|
80 |
| - return new RequestException($exception->getMessage(), $exception->getRequest(), $exception); |
| 88 | + return new TransferException($exception->getMessage(), 0, $exception); |
81 | 89 | }
|
82 | 90 | }
|
0 commit comments