summaryrefslogtreecommitdiffstats
path: root/lib/SparkPost/SparkPostException.php
blob: 92be3d55a8561a2fbdc327fa29d92ac9c2e671a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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;
    }
}

?>