Skip to content

Commit 7921438

Browse files
authored
all exceptions now have suffix (#553)
1 parent fde2049 commit 7921438

53 files changed

Lines changed: 226 additions & 227 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ And delete the old secret (any application still using these credentials will st
10251025
```php
10261026
try {
10271027
$response = $client->account()->deleteSecret(API_KEY, 'd0f40c7e-91f2-4fe0-8bc6-8942587b622c');
1028-
} catch(\Vonage\Client\Exception\Request $e) {
1028+
} catch(\Vonage\Client\Exception\RequestException $e) {
10291029
echo $e->getMessage();
10301030
}
10311031
```
@@ -1383,7 +1383,7 @@ $vonage_client = new Vonage\Client(new Vonage\Client\Credentials\Basic($api_key,
13831383

13841384
### Accessing Response Data
13851385

1386-
When things go wrong, you'll receive an `Exception`. The Vonage exception classes `Vonage\Client\Exception\Request` and `Vonage\Client\Exception\Server` support an additional `getEntity()` method which you can use in addition to `getCode()` and `getMessage()` to find out more about what went wrong. The entity returned will typically be an object related to the operation, or the response object from the API call.
1386+
When things go wrong, you'll receive an `Exception`. The Vonage exception classes `Vonage\Client\Exception\RequestException` and `Vonage\Client\Exception\ServerException` support an additional `getEntity()` method which you can use in addition to `getCode()` and `getMessage()` to find out more about what went wrong. The entity returned will typically be an object related to the operation, or the response object from the API call.
13871387

13881388
### Composer installation fails due to Guzzle Adapter
13891389

src/Account/Client.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Vonage\Client\APIClient;
99
use Vonage\Client\APIResource;
1010
use Vonage\Client\Exception as ClientException;
11-
use Vonage\Client\Exception\Request as ClientRequestException;
11+
use Vonage\Client\Exception\RequestException as ClientRequestException;
1212
use Vonage\Entity\Filter\KeyValueFilter;
1313

1414
use function count;
@@ -64,7 +64,7 @@ public function getPrefixPricing(string $prefix): array
6464
* @throws ClientExceptionInterface
6565
* @throws ClientRequestException
6666
* @throws ClientException\Exception
67-
* @throws ClientException\Server
67+
* @throws ClientException\ServerException
6868
*/
6969
public function getSmsPrice(string $country): SmsPrice
7070
{
@@ -81,7 +81,7 @@ public function getSmsPrice(string $country): SmsPrice
8181
* @throws ClientExceptionInterface
8282
* @throws ClientRequestException
8383
* @throws ClientException\Exception
84-
* @throws ClientException\Server
84+
* @throws ClientException\ServerException
8585
*/
8686
public function getVoicePrice(string $country): VoicePrice
8787
{
@@ -95,7 +95,7 @@ public function getVoicePrice(string $country): VoicePrice
9595
/**
9696
* @throws ClientRequestException
9797
* @throws ClientException\Exception
98-
* @throws ClientException\Server
98+
* @throws ClientException\ServerException
9999
* @throws ClientExceptionInterface
100100
*
101101
* @todo This should return an empty result instead of throwing an Exception on no results
@@ -108,7 +108,7 @@ protected function makePricingRequest($country, $pricingType): array
108108
$pageData = $results->getPageData();
109109

110110
if (is_null($pageData)) {
111-
throw new ClientException\Server('No results found');
111+
throw new ClientException\ServerException('No results found');
112112
}
113113

114114
return $pageData;
@@ -119,7 +119,7 @@ protected function makePricingRequest($country, $pricingType): array
119119
*
120120
* @throws ClientExceptionInterface
121121
* @throws ClientException\Exception
122-
* @throws ClientException\Server
122+
* @throws ClientException\ServerException
123123
*
124124
* @todo This needs further investigated to see if '' can even be returned from this endpoint
125125
*/
@@ -128,7 +128,7 @@ public function getBalance(): Balance
128128
$data = $this->getAPIResource()->get('get-balance', [], ['accept' => 'application/json']);
129129

130130
if (is_null($data)) {
131-
throw new ClientException\Server('No results found');
131+
throw new ClientException\ServerException('No results found');
132132
}
133133

134134
return new Balance($data['value'], $data['autoReload']);
@@ -150,7 +150,7 @@ public function topUp(string $trx): void
150150
*
151151
* @throws ClientExceptionInterface
152152
* @throws ClientException\Exception
153-
* @throws ClientException\Server
153+
* @throws ClientException\ServerException
154154
*/
155155
public function getConfig(): Config
156156
{
@@ -159,7 +159,7 @@ public function getConfig(): Config
159159
$body = $api->submit();
160160

161161
if ($body === '') {
162-
throw new ClientException\Server('Response was empty');
162+
throw new ClientException\ServerException('Response was empty');
163163
}
164164

165165
$body = json_decode($body, true);
@@ -178,7 +178,7 @@ public function getConfig(): Config
178178
*
179179
* @throws ClientExceptionInterface
180180
* @throws ClientException\Exception
181-
* @throws ClientException\Server
181+
* @throws ClientException\ServerException
182182
*/
183183
public function updateConfig(array $options): Config
184184
{
@@ -199,7 +199,7 @@ public function updateConfig(array $options): Config
199199
$rawBody = $api->submit($params);
200200

201201
if ($rawBody === '') {
202-
throw new ClientException\Server('Response was empty');
202+
throw new ClientException\ServerException('Response was empty');
203203
}
204204

205205
$body = json_decode($rawBody, true);

src/Client/APIExceptionHandler.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function getRfc7807Format(): string
3333
/**
3434
* @throws Exception\Exception
3535
*
36-
* @return Exception\Request|Exception\Server
36+
* @return Exception\RequestException|Exception\ServerException
3737
*/
3838
public function __invoke(ResponseInterface $response, RequestInterface $request)
3939
{
@@ -75,11 +75,11 @@ public function __invoke(ResponseInterface $response, RequestInterface $request)
7575
}
7676

7777
if ($status >= 400 && $status < 500) {
78-
$e = new Exception\Request($errorTitle, $status);
78+
$e = new Exception\RequestException($errorTitle, $status);
7979
@$e->setRequest($request);
8080
@$e->setResponse($response);
8181
} elseif ($status >= 500 && $status < 600) {
82-
$e = new Exception\Server($errorTitle, $status);
82+
$e = new Exception\ServerException($errorTitle, $status);
8383
@$e->setRequest($request);
8484
@$e->setResponse($response);
8585
} else {

src/Client/Exception/Conflict.php renamed to src/Client/Exception/ConflictException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44

55
namespace Vonage\Client\Exception;
66

7-
class Conflict extends \Exception
7+
class ConflictException extends \Exception
88
{
99
}

src/Client/Exception/Transport.php renamed to src/Client/Exception/CredentialsException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44

55
namespace Vonage\Client\Exception;
66

7-
class Transport extends Exception
7+
class CredentialsException extends \Exception
88
{
99
}

src/Client/Exception/Credentials.php renamed to src/Client/Exception/NotFoundException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44

55
namespace Vonage\Client\Exception;
66

7-
class Credentials extends \Exception
7+
class NotFoundException extends \Exception
88
{
99
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Vonage\Entity\HasEntityTrait;
88
use Vonage\Entity\Psr7Trait;
99

10-
class Request extends Exception
10+
class RequestException extends Exception
1111
{
1212
use HasEntityTrait;
1313
use Psr7Trait;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Vonage\Entity\HasEntityTrait;
88
use Vonage\Entity\Psr7Trait;
99

10-
class Server extends Exception
10+
class ServerException extends Exception
1111
{
1212
use HasEntityTrait;
1313
use Psr7Trait;

src/Client/Exception/ThrottleException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Vonage\Client\Exception;
66

7-
class ThrottleException extends Server
7+
class ThrottleException extends ServerException
88
{
99
/**
1010
* @var int

src/Client/Exception/NotFound.php renamed to src/Client/Exception/TransportException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44

55
namespace Vonage\Client\Exception;
66

7-
class NotFound extends \Exception
7+
class TransportException extends Exception
88
{
99
}

0 commit comments

Comments
 (0)