feat: optional logging of bpn requests/responses for debugging

This commit is contained in:
Björn Fromme
2024-02-16 14:43:05 +01:00
parent 4f95cd3dfc
commit 537e5b3c88
3 changed files with 25 additions and 7 deletions
+20
View File
@@ -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);
}