Skip to content
This repository was archived by the owner on Jan 6, 2024. It is now read-only.

Commit dcc8853

Browse files
gmponosdbu
authored andcommitted
Throw PSR-18 exceptions (#62)
1 parent 9509df0 commit dcc8853

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
99

1010
## [Unreleased]
1111

12+
### Changed
13+
- Function `sendRequest` of `\Http\Adapter\Guzzle6\Client` used to throw a `\UnexpectedValueException`. Now it throws a
14+
`Http\Adapter\Guzzle6\Exception\UnexpectedValueException` that extends the `\UnexpectedValueException` and implements
15+
the `Psr\Http\Client\ClientExceptionInterface`. This is done in order to be PSR-18 compliant.
16+
17+
- Function `sendRequest` of `\Http\Adapter\Guzzle6\Client` used to throw a `\RuntimeException`. Now it throws a
18+
`Http\Client\Exception\TransferException` that extends the `\RuntimeException` and implements
19+
the `Psr\Http\Client\ClientExceptionInterface`. This is done in order to be PSR-18 compliant.
1220

1321
## [2.0.0] - 2018-11-14
1422

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace Http\Adapter\Guzzle6\Exception;
4+
5+
use Http\Client\Exception;
6+
7+
final class UnexpectedValueException extends \UnexpectedValueException implements Exception
8+
{
9+
}

src/Promise.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use GuzzleHttp\Exception as GuzzleExceptions;
66
use GuzzleHttp\Promise\PromiseInterface;
7+
use Http\Adapter\Guzzle6\Exception\UnexpectedValueException;
78
use Http\Client\Exception as HttplugException;
89
use Http\Promise\Promise as HttpPromise;
910
use Psr\Http\Message\RequestInterface;
@@ -62,9 +63,9 @@ public function __construct(PromiseInterface $promise, RequestInterface $request
6263
} elseif ($reason instanceof GuzzleExceptions\GuzzleException) {
6364
$this->exception = $this->handleException($reason, $request);
6465
} elseif ($reason instanceof \Throwable) {
65-
$this->exception = new \RuntimeException('Invalid exception returned from Guzzle6', 0, $reason);
66+
$this->exception = new HttplugException\TransferException('Invalid exception returned from Guzzle6', 0, $reason);
6667
} else {
67-
$this->exception = new \UnexpectedValueException('Reason returned from Guzzle6 must be an Exception');
68+
$this->exception = new UnexpectedValueException('Reason returned from Guzzle6 must be an Exception');
6869
}
6970

7071
throw $this->exception;

tests/PromiseExceptionTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Http\Adapter\Guzzle6\Tests;
66

77
use GuzzleHttp\Exception as GuzzleExceptions;
8+
use Http\Adapter\Guzzle6\Exception\UnexpectedValueException;
89
use Http\Adapter\Guzzle6\Promise;
910
use Http\Client\Exception\HttpException;
1011
use Http\Client\Exception\NetworkException;
@@ -54,9 +55,9 @@ public function exceptionThatIsThrownForGuzzleExceptionProvider(): array
5455
[$request, new GuzzleExceptions\ClientException('foo', $request), RequestException::class],
5556
[$request, new GuzzleExceptions\ServerException('foo', $request), RequestException::class],
5657
// Non PSR-18 Exceptions thrown
57-
[$request, new \Exception('foo'), \RuntimeException::class],
58-
[$request, new \Error('foo'), \RuntimeException::class],
59-
[$request, 'whatever', \UnexpectedValueException::class],
58+
[$request, new \Exception('foo'), TransferException::class],
59+
[$request, new \Error('foo'), TransferException::class],
60+
[$request, 'whatever', UnexpectedValueException::class],
6061
];
6162
}
6263
}

0 commit comments

Comments
 (0)