From b76e2ff898b23745d4c9aaee49eeb7d88f2896ab Mon Sep 17 00:00:00 2001 From: Carson Fleming Date: Thu, 2 Mar 2017 22:49:24 -0500 Subject: Updated mailgun plugin --- .../httplug/src/Exception/HttpException.php | 74 ++++++++++++++++++++++ .../httplug/src/Exception/NetworkException.php | 14 ++++ .../httplug/src/Exception/RequestException.php | 43 +++++++++++++ .../httplug/src/Exception/TransferException.php | 14 ++++ 4 files changed, 145 insertions(+) create mode 100644 inc/mailgun/php-http/httplug/src/Exception/HttpException.php create mode 100644 inc/mailgun/php-http/httplug/src/Exception/NetworkException.php create mode 100644 inc/mailgun/php-http/httplug/src/Exception/RequestException.php create mode 100644 inc/mailgun/php-http/httplug/src/Exception/TransferException.php (limited to 'inc/mailgun/php-http/httplug/src/Exception') diff --git a/inc/mailgun/php-http/httplug/src/Exception/HttpException.php b/inc/mailgun/php-http/httplug/src/Exception/HttpException.php new file mode 100644 index 0000000..f4f32a4 --- /dev/null +++ b/inc/mailgun/php-http/httplug/src/Exception/HttpException.php @@ -0,0 +1,74 @@ + + */ +class HttpException extends RequestException +{ + /** + * @var ResponseInterface + */ + protected $response; + + /** + * @param string $message + * @param RequestInterface $request + * @param ResponseInterface $response + * @param \Exception|null $previous + */ + public function __construct( + $message, + RequestInterface $request, + ResponseInterface $response, + \Exception $previous = null + ) { + parent::__construct($message, $request, $previous); + + $this->response = $response; + $this->code = $response->getStatusCode(); + } + + /** + * Returns the response. + * + * @return ResponseInterface + */ + public function getResponse() + { + return $this->response; + } + + /** + * Factory method to create a new exception with a normalized error message. + * + * @param RequestInterface $request + * @param ResponseInterface $response + * @param \Exception|null $previous + * + * @return HttpException + */ + public static function create( + RequestInterface $request, + ResponseInterface $response, + \Exception $previous = null + ) { + $message = sprintf( + '[url] %s [http method] %s [status code] %s [reason phrase] %s', + $request->getRequestTarget(), + $request->getMethod(), + $response->getStatusCode(), + $response->getReasonPhrase() + ); + + return new self($message, $request, $response, $previous); + } +} diff --git a/inc/mailgun/php-http/httplug/src/Exception/NetworkException.php b/inc/mailgun/php-http/httplug/src/Exception/NetworkException.php new file mode 100644 index 0000000..f2198e5 --- /dev/null +++ b/inc/mailgun/php-http/httplug/src/Exception/NetworkException.php @@ -0,0 +1,14 @@ + + */ +class NetworkException extends RequestException +{ +} diff --git a/inc/mailgun/php-http/httplug/src/Exception/RequestException.php b/inc/mailgun/php-http/httplug/src/Exception/RequestException.php new file mode 100644 index 0000000..cdce14b --- /dev/null +++ b/inc/mailgun/php-http/httplug/src/Exception/RequestException.php @@ -0,0 +1,43 @@ + + */ +class RequestException extends TransferException +{ + /** + * @var RequestInterface + */ + private $request; + + /** + * @param string $message + * @param RequestInterface $request + * @param \Exception|null $previous + */ + public function __construct($message, RequestInterface $request, \Exception $previous = null) + { + $this->request = $request; + + parent::__construct($message, 0, $previous); + } + + /** + * Returns the request. + * + * @return RequestInterface + */ + public function getRequest() + { + return $this->request; + } +} diff --git a/inc/mailgun/php-http/httplug/src/Exception/TransferException.php b/inc/mailgun/php-http/httplug/src/Exception/TransferException.php new file mode 100644 index 0000000..a858cf5 --- /dev/null +++ b/inc/mailgun/php-http/httplug/src/Exception/TransferException.php @@ -0,0 +1,14 @@ + + */ +class TransferException extends \RuntimeException implements Exception +{ +} -- cgit v1.2.3