1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Promopult\TikTokMarketingApi\Exception; |
4
|
|
|
|
5
|
|
|
use GuzzleHttp\Psr7\Message; |
6
|
|
|
use Psr\Http\Message\RequestInterface; |
7
|
|
|
use Psr\Http\Message\ResponseInterface; |
8
|
|
|
|
9
|
|
|
class MalformedResponse extends \RuntimeException |
10
|
|
|
{ |
11
|
|
|
private RequestInterface $request; |
12
|
|
|
private ResponseInterface $response; |
13
|
|
|
|
14
|
|
|
public function __construct( |
15
|
|
|
RequestInterface $request, |
16
|
|
|
ResponseInterface $response, |
17
|
|
|
string $message = 'Unexpected Tik-Tok API response.', |
18
|
|
|
int $code = 0, |
19
|
|
|
\Throwable $previous = null |
20
|
|
|
) { |
21
|
|
|
parent::__construct($message, $code, $previous); |
22
|
|
|
$this->request = $request; |
23
|
|
|
$this->response = $response; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function getRequest(): RequestInterface |
27
|
|
|
{ |
28
|
|
|
return $this->request; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function getResponse(): ResponseInterface |
32
|
|
|
{ |
33
|
|
|
return $this->response; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function getResponseAsString(): string |
37
|
|
|
{ |
38
|
|
|
return Message::toString($this->response); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function getRequestAsString(): string |
42
|
|
|
{ |
43
|
|
|
return Message::toString($this->request); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function __toString(): string |
47
|
|
|
{ |
48
|
|
|
return parent::__toString() . PHP_EOL |
49
|
|
|
. 'Http log:' . PHP_EOL |
50
|
|
|
. '>>>' . PHP_EOL . $this->getRequestAsString() . PHP_EOL |
51
|
|
|
. '<<<' . PHP_EOL . $this->getResponseAsString() |
52
|
|
|
; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|