Skip to content

Commit 43bf020

Browse files
authored
Optimized GuzzleHttpClientAspect (#837)
* Optimized `GuzzleHttpClientAspect` * 优化 GuzzleHttpClientAspect 中的响应数据记录逻辑 --------- Co-authored-by: Deeka Wong <8337659+huangdijia@users.noreply.github.com>
1 parent 186ed1f commit 43bf020

1 file changed

Lines changed: 12 additions & 13 deletions

File tree

src/Aspect/GuzzleHttpClientAspect.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,23 +64,22 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint)
6464
try {
6565
$request = $stats->getRequest();
6666
$response = $stats->getResponse();
67-
$data = [
68-
'status' => $response->getStatusCode(),
69-
'reason' => $response->getReasonPhrase(),
70-
'headers' => $response->getHeaders(),
71-
'body' => $this->getResponsePayload($response),
72-
];
73-
74-
Telescope::recordClientRequest(IncomingEntry::make([
67+
$content = [
7568
'method' => $request->getMethod(),
7669
'uri' => $request->getUri()->__toString(),
7770
'headers' => $request->getHeaders(),
78-
'response_status' => $data['status'],
79-
'response_headers' => $data['headers'],
80-
'response_data' => $data,
8171
'duration' => $stats->getTransferTime() * 1000,
82-
]));
83-
} catch (Throwable $e) {
72+
];
73+
74+
if ($response = $stats->getResponse()) {
75+
$content['response_status'] = $response->getStatusCode();
76+
$content['response_headers'] = $response->getHeaders();
77+
$content['response_reason'] = $response->getReasonPhrase();
78+
$content['response_payload'] = $this->getResponsePayload($response);
79+
}
80+
81+
Telescope::recordClientRequest(IncomingEntry::make($content));
82+
} catch (Throwable $exception) {
8483
// We will catch the exception to prevent the request from being interrupted.
8584
}
8685

0 commit comments

Comments
 (0)