Skip to content

Commit

Permalink
Change ApiErrorException to ClientException.
Browse files Browse the repository at this point in the history
  • Loading branch information
polidog committed Jan 28, 2018
1 parent 0e653ef commit 516e80a
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 52 deletions.
7 changes: 4 additions & 3 deletions src/Client/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = [])
{
Expand All @@ -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);
}
}

Expand Down
48 changes: 0 additions & 48 deletions src/Exception/ApiErrorException.php

This file was deleted.

63 changes: 63 additions & 0 deletions src/Exception/ClientException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace Polidog\Esa\Exception;

class ClientException extends \RuntimeException
{
/**
* @var string
*/
private $method;

/**
* @var string
*/
private $path;

/**
* @var array
*/
private $params;

/**
* @return string
*/
public function getMethod()
{
return $this->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;
}
}
2 changes: 1 addition & 1 deletion tests/Client/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function testRequest()
}

/**
* @expectedException \Polidog\Esa\Exception\ApiErrorException
* @expectedException \Polidog\Esa\Exception\ClientException
*/
public function testRequestException()
{
Expand Down

0 comments on commit 516e80a

Please sign in to comment.