summaryrefslogtreecommitdiffstats
path: root/lib/SparkPost/SparkPostException.php
diff options
context:
space:
mode:
authorAvi Goldman <avrahamymgoldman@gmail.com>2016-06-20 12:51:11 -0400
committerAvi Goldman <avrahamymgoldman@gmail.com>2016-06-20 12:51:11 -0400
commit1187a2ccc7209b2fc4deded9e61c5124698df795 (patch)
tree025473f3c29dea39763207ceddd26c4a407763fc /lib/SparkPost/SparkPostException.php
parent0942bed79ca5e8162213405ea16350ae855d9546 (diff)
parent87552cc2766f4ea8c8a2d6ff6c70dd74faecb687 (diff)
downloadphp-sparkpost-1187a2ccc7209b2fc4deded9e61c5124698df795.zip
php-sparkpost-1187a2ccc7209b2fc4deded9e61c5124698df795.tar.gz
php-sparkpost-1187a2ccc7209b2fc4deded9e61c5124698df795.tar.bz2
merged in 2.x
Diffstat (limited to 'lib/SparkPost/SparkPostException.php')
-rw-r--r--lib/SparkPost/SparkPostException.php33
1 files changed, 24 insertions, 9 deletions
diff --git a/lib/SparkPost/SparkPostException.php b/lib/SparkPost/SparkPostException.php
index 92be3d5..f1e3146 100644
--- a/lib/SparkPost/SparkPostException.php
+++ b/lib/SparkPost/SparkPostException.php
@@ -4,23 +4,38 @@ namespace SparkPost;
use Http\Client\Exception\HttpException as HttpException;
-class SparkPostException extends \Exception {
-
+class SparkPostException extends \Exception
+{
+ /**
+ * Variable to hold json decoded body from http response.
+ */
private $body = null;
- public function __construct(\Exception $exception) {
+ /**
+ * Sets up the custom exception and copies over original exception values.
+ *
+ * @param Exception $exception - the exception to be wrapped
+ */
+ public function __construct(\Exception $exception)
+ {
$message = $exception->getMessage();
- if($exception instanceof HttpException) {
+ $code = $exception->getCode();
+ if ($exception instanceof HttpException) {
$message = $exception->getResponse()->getBody()->__toString();
$this->body = json_decode($message, true);
+ $code = $exception->getResponse()->getStatusCode();
}
- parent::__construct($message, $exception->getCode(), $exception->getPrevious());
+ parent::__construct($message, $code, $exception->getPrevious());
}
- public function getBody() {
+ /**
+ * Returns the body.
+ *
+ * @return array $body - the json decoded body from the http response
+ */
+ public function getBody()
+ {
return $this->body;
}
-}
-
-?> \ No newline at end of file
+} \ No newline at end of file