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
+1
View File
@@ -45,6 +45,7 @@ APP_BASE_URI=https://myep-team.ddev.site
APP_BPN_USER=
APP_BPN_PASSWORD=
APP_BPN_ENDPOINT=
APP_BPN_DEBUG=false
# This hotel code will be assigned to admin users together with ROLE_HOTEL_MANAGER
# in dev and staging environments for testing purposes
+4 -7
View File
@@ -1,8 +1,4 @@
parameters:
bpn_url: '%env(APP_BPN_ENDPOINT)%'
bpn_username: '%env(APP_BPN_USER)%'
bpn_password: '%env(APP_BPN_PASSWORD)%'
bpn_crm_id_admin: '%env(int:APP_BPN_CRM_ID_ADMIN)%'
bpn_crm_id_manager: '%env(int:APP_BPN_CRM_ID_MANAGER)%'
bpn_crm_id_teamer: '%env(int:APP_BPN_CRM_ID_TEAMER)%'
@@ -42,9 +38,10 @@ services:
arguments:
$logger: '@monolog.logger.bpn'
$options:
bpn_username: '%bpn_username%'
bpn_password: '%bpn_password%'
bpn_url: '%bpn_url%'
bpn_username: '%env(APP_BPN_USER)%'
bpn_password: '%env(APP_BPN_PASSWORD)%'
bpn_url: '%env(APP_BPN_ENDPOINT)%'
debug: '%env(bool:APP_BPN_DEBUG)%'
App\BusProNet\ResponseParser:
arguments:
+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);
}