-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSymfonyHttpClientMessage.php
More file actions
38 lines (34 loc) · 999 Bytes
/
SymfonyHttpClientMessage.php
File metadata and controls
38 lines (34 loc) · 999 Bytes
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
27
28
29
30
31
32
33
34
35
36
37
38
<?php
namespace WebmanTech\Logger\Message;
use Symfony\Contracts\HttpClient\ResponseInterface;
use Throwable;
use WebmanTech\Logger\Helper\StringHelper;
/**
* Symfony HttpClient 请求日志
*/
class SymfonyHttpClientMessage extends BaseHttpClientMessage
{
protected function getResponseStatus(mixed $response): int
{
if (!$response instanceof ResponseInterface) {
return 0;
}
try {
return $response->getStatusCode();
} catch (Throwable) {
return 1;
}
}
protected function getResponseContent(mixed $response, int $limitLength): string
{
if (!$response instanceof ResponseInterface) {
return '[Response Type error]';
}
try {
$content = $response->getContent(false);
} catch (Throwable $e) {
return '[Response Content error: ' . $e->getMessage() . ']';
}
return StringHelper::limit($content, $limitLength);
}
}