summaryrefslogtreecommitdiff
path: root/inc/mailgun/php-http/httplug/src/Exception/HttpException.php
diff options
context:
space:
mode:
authorCarson Fleming <cflems@cflems.net>2017-03-02 22:49:24 -0500
committerCarson Fleming <cflems@cflems.net>2017-03-02 22:49:24 -0500
commitb76e2ff898b23745d4c9aaee49eeb7d88f2896ab (patch)
tree9b794be8db310a575d70165d9ebde0a183b61b01 /inc/mailgun/php-http/httplug/src/Exception/HttpException.php
parentbfcc9f7a7656a2db0c905b3c13114664f00f6c37 (diff)
downloadbulletin-b76e2ff898b23745d4c9aaee49eeb7d88f2896ab.tar.gz
Updated mailgun plugin
Diffstat (limited to 'inc/mailgun/php-http/httplug/src/Exception/HttpException.php')
-rw-r--r--inc/mailgun/php-http/httplug/src/Exception/HttpException.php74
1 files changed, 74 insertions, 0 deletions
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 @@
+<?php
+
+namespace Http\Client\Exception;
+
+use Psr\Http\Message\RequestInterface;
+use Psr\Http\Message\ResponseInterface;
+
+/**
+ * Thrown when a response was received but the request itself failed.
+ *
+ * In addition to the request, this exception always provides access to the response object.
+ *
+ * @author Márk Sági-Kazár <mark.sagikazar@gmail.com>
+ */
+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);
+ }
+}