diff options
Diffstat (limited to 'lib/SparkPost/SparkPostException.php')
-rw-r--r-- | lib/SparkPost/SparkPostException.php | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/SparkPost/SparkPostException.php b/lib/SparkPost/SparkPostException.php new file mode 100644 index 0000000..92be3d5 --- /dev/null +++ b/lib/SparkPost/SparkPostException.php @@ -0,0 +1,26 @@ +<?php + +namespace SparkPost; + +use Http\Client\Exception\HttpException as HttpException; + +class SparkPostException extends \Exception { + + private $body = null; + + public function __construct(\Exception $exception) { + $message = $exception->getMessage(); + if($exception instanceof HttpException) { + $message = $exception->getResponse()->getBody()->__toString(); + $this->body = json_decode($message, true); + } + + parent::__construct($message, $exception->getCode(), $exception->getPrevious()); + } + + public function getBody() { + return $this->body; + } +} + +?>
\ No newline at end of file |