Skip to content

Commit 602f738

Browse files
authored
Merge pull request #41 from spotlibs/feature/logging-request-and-response-body-as-is-string-if-not-json
change logging in ClientExternal. check response Content-Type before …
2 parents 4a68978 + ab6dc57 commit 602f738

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/Libraries/ClientExternal.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,23 @@ public function call(Request $request, array $options = []): ResponseInterface
169169
'request' => [
170170
'method' => $request->getMethod(),
171171
'headers' => $request->getHeaders(),
172-
'body' => json_decode($reqbody, true)
173172
],
174173
'response' => [
175174
'headers' => $response->getHeaders(),
176-
'body' => json_decode($respbody, true)
177175
],
178176
'responseTime' => round($elapsed * 1000),
179177
'memoryUsage' => memory_get_usage()
180178
];
179+
if ($request->getHeader('Content-Type') == 'application/json') {
180+
$logData['request']['body'] = json_decode($reqbody, true);
181+
} else {
182+
$logData['request']['body'] = $reqbody;
183+
}
184+
if ($response->getHeader('Content-Type') == 'application/json') {
185+
$logData['response']['body'] = json_decode($respbody, true);
186+
} else {
187+
$logData['response']['body'] = $respbody;
188+
}
181189
$response->getBody()->rewind();
182190
Log::activity()->info($logData);
183191
}

0 commit comments

Comments
 (0)