feat: optional logging of bpn requests/responses for debugging
This commit is contained in:
@@ -10,6 +10,7 @@ use App\Entity\User;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Serializer\SerializerInterface;
|
||||
use Symfony\Component\Uid\Uuid;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
class ApiClient
|
||||
@@ -134,11 +135,20 @@ class ApiClient
|
||||
*/
|
||||
private function sendRequest(string $type, array $data): mixed
|
||||
{
|
||||
$requestId = (string) Uuid::v4();
|
||||
|
||||
$body = $this
|
||||
->serializer
|
||||
->serialize($data, 'xml')
|
||||
;
|
||||
|
||||
if (true === $this->config['debug']) {
|
||||
$this->logger->info('Request sent', [
|
||||
'id' => $requestId,
|
||||
'request' => $body,
|
||||
]);
|
||||
}
|
||||
|
||||
try {
|
||||
$response = $this->httpClient->request('GET', $this->config['bpn_url'], [
|
||||
'query' => [
|
||||
@@ -148,6 +158,13 @@ class ApiClient
|
||||
|
||||
$xml = $response->getContent();
|
||||
|
||||
if (true === $this->config['debug']) {
|
||||
$this->logger->info('Response received', [
|
||||
'id' => $requestId,
|
||||
'response' => $xml,
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->responseParser->parseXmlString($type, $xml);
|
||||
} catch (\Throwable $e) {
|
||||
}
|
||||
@@ -167,6 +184,9 @@ class ApiClient
|
||||
{
|
||||
$optionsResolver = new OptionsResolver();
|
||||
$optionsResolver->setRequired(['bpn_url', 'bpn_username', 'bpn_password']);
|
||||
$optionsResolver->setDefaults([
|
||||
'debug' => false,
|
||||
]);
|
||||
|
||||
return $optionsResolver->resolve($options);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user