Skip to content

Commit

Permalink
Service::sendRequest now throws Mekras\OData\Client\Exception\Network…
Browse files Browse the repository at this point in the history
…Exception in case of network errors.
  • Loading branch information
mekras committed Sep 12, 2016
1 parent 9337ef4 commit 9e6cdd7
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Change Log

## 0.3.5 - 2016-09-12

### Added

- `Mekras\OData\Client\Exception\NetworkException`

### Changed

- `Service::sendRequest` now throws `Mekras\OData\Client\Exception\NetworkException` in case of
network errors.


## 0.3.4 - 2016-09-01

### Changed
Expand Down
1 change: 1 addition & 0 deletions docs/service.ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function sendRequest(string $method, string $uri,
- `\InvalidArgumentException` если тип документа $document не поддерживается.
- `\Mekras\Atom\Exception\RuntimeException` в случае ошибок в XML, полученном от сервера.
- `\Mekras\OData\Client\Exception\ClientErrorException` если сервер сообщает об ошибке клиента.
- `\Mekras\OData\Client\Exception\NetworkException` в случае сетевых проблем.
- `\Mekras\OData\Client\Exception\ServerErrorException` в случае ошибки на стороне сервера.
- `\Mekras\OData\Client\Exception\RuntimeException` в остальных случаях.

Expand Down
17 changes: 17 additions & 0 deletions src/Exception/NetworkException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
/**
* OData client library
*
* @author Михаил Красильников <m.krasilnikov@yandex.ru>
* @license MIT
*/
namespace Mekras\OData\Client\Exception;

/**
* Network exception.
*
* @since 0.3
*/
class NetworkException extends RuntimeException
{
}
4 changes: 4 additions & 0 deletions src/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Mekras\Atom\Document\Document;
use Mekras\OData\Client\Document\ErrorDocument;
use Mekras\OData\Client\Exception\ClientErrorException;
use Mekras\OData\Client\Exception\NetworkException;
use Mekras\OData\Client\Exception\RuntimeException;
use Mekras\OData\Client\Exception\ServerErrorException;
use Psr\Http\Message\ResponseInterface;
Expand Down Expand Up @@ -90,6 +91,7 @@ public function __construct(
* @throws \InvalidArgumentException If given document is not supported.
* @throws \Mekras\Atom\Exception\RuntimeException In case of XML errors.
* @throws \Mekras\OData\Client\Exception\ClientErrorException On client error.
* @throws \Mekras\OData\Client\Exception\NetworkException In case of network error.
* @throws \Mekras\OData\Client\Exception\RuntimeException On other errors.
* @throws \Mekras\OData\Client\Exception\ServerErrorException On server error.
*
Expand Down Expand Up @@ -119,6 +121,8 @@ public function sendRequest($method, $uri, Document $document = null)

try {
$response = $this->httpClient->sendRequest($request);
} catch (HttpClientException\NetworkException $e) {
throw new NetworkException($e->getMessage(), $e->getCode(), $e);
} catch (\Exception $e) {
throw new RuntimeException($e->getMessage(), 0, $e);
}
Expand Down

0 comments on commit 9e6cdd7

Please sign in to comment.