Completed
Push — master ( b626c0...1ad737 )
by Camilo
03:37
created

ClientException::getError()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace unreal4u\TelegramAPI\Exceptions;
6
7
use Throwable;
8
use unreal4u\TelegramAPI\Telegram\Types\Custom\UnsuccessfulRequest;
9
10
class ClientException extends \RuntimeException
11
{
12
    /**
13
     * @var UnsuccessfulRequest
14
     */
15
    protected $errorRequest;
16
17 2
    public function __construct(string $message = '', int $code = 0, Throwable $previous = null)
18
    {
19 2
        parent::__construct($message, $code, $previous);
20
21 2
        if ($previous !== null) {
22
            $this->file = $previous->getFile();
23
            $this->line = $previous->getLine();
24
25
            $this->setError(new UnsuccessfulRequest([
26
                'description' => $previous->getMessage(),
27
                'error_code' => $previous->getCode(),
28
            ]));
29
        }
30 2
    }
31
32 2
    public function setError(UnsuccessfulRequest $unsuccessfulRequest): ClientException
33
    {
34 2
        $this->errorRequest = $unsuccessfulRequest;
35
36 2
        $this->message = $unsuccessfulRequest->description;
37 2
        $this->code = $unsuccessfulRequest->error_code;
38 2
        return $this;
39
    }
40
41
    public function getError(): UnsuccessfulRequest
42
    {
43
        return $this->errorRequest;
44
    }
45
}
46