diff --git a/src/Client/Client.php b/src/Client/Client.php index a6bb9b6..1a39852 100644 --- a/src/Client/Client.php +++ b/src/Client/Client.php @@ -6,7 +6,7 @@ use GuzzleHttp\Exception\GuzzleException; use GuzzleHttp\HandlerStack; use GuzzleHttp\Middleware; -use Polidog\Esa\Exception\ApiErrorException; +use Polidog\Esa\Exception\ClientException; use Psr\Http\Message\RequestInterface; final class Client implements ClientInterface @@ -51,7 +51,8 @@ public function __construct($accessToken, HttpClientInterface $httpClient) * * @return array * - * @throws ApiErrorException + * @throws ClientException + * @throws \RuntimeException */ public function request($method, $path, array $data = []) { @@ -60,7 +61,7 @@ public function request($method, $path, array $data = []) return json_decode($response->getBody()->getContents(), true); } catch (GuzzleException $e) { - throw ApiErrorException::newException($e, $path, $data); + throw ClientException::newException($e, $method, $path, $data); } } diff --git a/src/Exception/ApiErrorException.php b/src/Exception/ApiErrorException.php deleted file mode 100644 index 53fb361..0000000 --- a/src/Exception/ApiErrorException.php +++ /dev/null @@ -1,48 +0,0 @@ -apiMethodName; - } - - /** - * @return array - */ - public function getArgs() - { - return $this->args; - } - - /** - * @param \Exception $e - * @param $name - * @param array $args - * - * @return ApiErrorException - */ - public static function newException(\Exception $e, $name, array $args) - { - $self = new self(sprintf('Api method error: %s', $name), $e->getCode(), $e); - $self->apiMethodName = $name; - $self->args = $args; - - return $self; - } -} diff --git a/src/Exception/ClientException.php b/src/Exception/ClientException.php new file mode 100644 index 0000000..e220a83 --- /dev/null +++ b/src/Exception/ClientException.php @@ -0,0 +1,63 @@ +method; + } + + /** + * @return string + */ + public function getPath() + { + return $this->path; + } + + /** + * @return array + */ + public function getParams() + { + return $this->params; + } + + /** + * @param \Exception $e + * @param $method + * @param $path + * @param array $params + * + * @return ClientException + */ + public static function newException(\Exception $e, $method, $path, array $params) + { + $self = new self(sprintf('Api method error: %s : %s', $method, $path), $e->getCode(), $e); + $self->method = $method; + $self->path = $path; + $self->params = $params; + + return $self; + } +} diff --git a/tests/Client/ClientTest.php b/tests/Client/ClientTest.php index 7c41fdb..7f31d6d 100644 --- a/tests/Client/ClientTest.php +++ b/tests/Client/ClientTest.php @@ -39,7 +39,7 @@ public function testRequest() } /** - * @expectedException \Polidog\Esa\Exception\ApiErrorException + * @expectedException \Polidog\Esa\Exception\ClientException */ public function testRequestException() {