From 826b6f2c1dd8a94239ad3808dad0bab7c3ee270b Mon Sep 17 00:00:00 2001 From: Martin Brecht-Precht Date: Tue, 26 Apr 2016 10:08:49 +0200 Subject: [PATCH] Added some more exception classes. Reorganized the namespace structure. Updated readme. --- README.md | 18 +++++++++++------- ...ception.php => AuthenticationException.php} | 4 ++-- src/ApiException/{ => Base}/ApiException.php | 4 +++- src/ApiException/Base/BaseException.php | 15 --------------- src/ApiException/InvalidResponseException.php | 13 +++++++++++++ ...mitException.php => NoResultsException.php} | 4 ++-- ...Exception.php => RequestQuotaException.php} | 4 ++-- .../{BaseException.php => IoException.php} | 2 +- src/IoException/FileCopyException.php | 13 +++++++++++++ src/IoException/FileDeleteException.php | 13 +++++++++++++ src/IoException/FileMoveException.php | 13 +++++++++++++ src/IoException/FileReadException.php | 13 +++++++++++++ src/IoException/FileWriteException.php | 2 +- src/NetworkException/Base/NetworkException.php | 15 +++++++++++++++ src/NetworkException/Base/TimeoutException.php | 13 +++++++++++++ src/NetworkException/ConnectionException.php | 13 +++++++++++++ .../ConnectionTimeoutException.php | 13 +++++++++++++ src/NetworkException/CurlException.php | 13 +++++++++++++ src/NetworkException/ReadTimeoutException.php | 13 +++++++++++++ src/NetworkException/WriteTimeoutException.php | 13 +++++++++++++ 20 files changed, 180 insertions(+), 31 deletions(-) rename src/ApiException/{ApiNoResultsException.php => AuthenticationException.php} (54%) rename src/ApiException/{ => Base}/ApiException.php (64%) delete mode 100644 src/ApiException/Base/BaseException.php create mode 100644 src/ApiException/InvalidResponseException.php rename src/ApiException/{ApiLimitException.php => NoResultsException.php} (57%) rename src/ApiException/{NetworkException.php => RequestQuotaException.php} (55%) rename src/IoException/Base/{BaseException.php => IoException.php} (74%) create mode 100644 src/IoException/FileCopyException.php create mode 100644 src/IoException/FileDeleteException.php create mode 100644 src/IoException/FileMoveException.php create mode 100644 src/IoException/FileReadException.php create mode 100644 src/NetworkException/Base/NetworkException.php create mode 100644 src/NetworkException/Base/TimeoutException.php create mode 100644 src/NetworkException/ConnectionException.php create mode 100644 src/NetworkException/ConnectionTimeoutException.php create mode 100644 src/NetworkException/CurlException.php create mode 100644 src/NetworkException/ReadTimeoutException.php create mode 100644 src/NetworkException/WriteTimeoutException.php diff --git a/README.md b/README.md index ef01de1..e88f57f 100644 --- a/README.md +++ b/README.md @@ -34,13 +34,15 @@ require_once('path/to/vendor/autoload.php'); ```{php} try{ // Perform something maybe throwing an exception -} catch (CommonException\ApiException\NetworkException $exception) { - // API is not reachable or curl failed -} catch (CommonException\ApiException\ApiException $exception) { +} catch (CommonException\NetworkException\ConnectionException $exception) { + // API is not reachable +} catch (CommonException\NetworkException\CurlException $exception) { + // Curl failed +} catch (CommonException\ApiException\InvalidResponseException $exception) { // API returns an unexpected result -} catch (CommonException\ApiException\ApiLimitException $exception) { +} catch (CommonException\ApiException\RequestQuotaException $exception) { // API requests over the allowed limit -} catch (CommonException\ApiException\ApiNoResultsException $exception) { +} catch (CommonException\ApiException\NoResultsException $exception) { // API request had no result } catch (CommonException\IoException\FileWriteException $exception) { // Log file was not writable @@ -53,9 +55,11 @@ try{ ```{php} try{ // Perform something maybe throwing an exception -} catch (CommonException\ApiException\Base\BaseException $exception) { +} catch (CommonException\NetworkException\Base\NetworkException $exception) { + // Any network exception was thrown +} catch (CommonException\ApiException\Base\ApiException $exception) { // Any API exception was thrown -} catch (CommonException\IoException\Base\BaseException $exception) { +} catch (CommonException\IoException\Base\IoException $exception) { // Any IO exception was thrown } diff --git a/src/ApiException/ApiNoResultsException.php b/src/ApiException/AuthenticationException.php similarity index 54% rename from src/ApiException/ApiNoResultsException.php rename to src/ApiException/AuthenticationException.php index 1db233f..ab86b2a 100644 --- a/src/ApiException/ApiNoResultsException.php +++ b/src/ApiException/AuthenticationException.php @@ -3,11 +3,11 @@ namespace CommonException\ApiException; /** - * Class ApiNoResultsException + * Class AuthenticationException * * @package CommonException\ApiException */ -class ApiNoResultsException extends Base\BaseException +class AuthenticationException extends Base\ApiException { } diff --git a/src/ApiException/ApiException.php b/src/ApiException/Base/ApiException.php similarity index 64% rename from src/ApiException/ApiException.php rename to src/ApiException/Base/ApiException.php index 9d8e827..a24f73e 100644 --- a/src/ApiException/ApiException.php +++ b/src/ApiException/Base/ApiException.php @@ -1,6 +1,8 @@