feat: add logging to contingent api endpoint

This commit is contained in:
Björn Fromme
2026-08-03 17:59:19 +02:00
parent efc385bf54
commit b54c8917c9
+12 -2
View File
@@ -14,6 +14,7 @@ use App\Repository\Groups\AccommodationPriceRepository;
use App\Repository\Groups\AccommodationRepository; use App\Repository\Groups\AccommodationRepository;
use App\Service\PriceTimelineBuilder; use App\Service\PriceTimelineBuilder;
use Psr\Cache\InvalidArgumentException; use Psr\Cache\InvalidArgumentException;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
@@ -33,6 +34,7 @@ class ContingentController extends AbstractController
private readonly AccommodationPriceRepository $priceRepository, private readonly AccommodationPriceRepository $priceRepository,
private readonly CacheInterface $cache, private readonly CacheInterface $cache,
private readonly PriceTimelineBuilder $priceTimelineBuilder, private readonly PriceTimelineBuilder $priceTimelineBuilder,
private readonly LoggerInterface $logger,
) { ) {
} }
@@ -44,7 +46,9 @@ class ContingentController extends AbstractController
$accommodation = $this->accommodationRepository->findOneBy(['calendarCode' => $query->hotelCode]); $accommodation = $this->accommodationRepository->findOneBy(['calendarCode' => $query->hotelCode]);
if (null === $accommodation) { if (null === $accommodation) {
return $this->json(['error' => 'hotel not found for hotelCode.'], Response::HTTP_BAD_REQUEST); $this->logger->error('Hotel not found for hotelcode '.$query->hotelCode);
return $this->json(['error' => 'Hotel not found for hotelCode.'], Response::HTTP_BAD_REQUEST);
} }
$yearStart = new \DateTimeImmutable("{$query->year}-01-01"); $yearStart = new \DateTimeImmutable("{$query->year}-01-01");
@@ -68,7 +72,9 @@ class ContingentController extends AbstractController
$accommodation = $this->accommodationRepository->findOneBy(['calendarCode' => $query->hotelCode]); $accommodation = $this->accommodationRepository->findOneBy(['calendarCode' => $query->hotelCode]);
if (null === $accommodation) { if (null === $accommodation) {
return $this->json(['error' => 'hotel not found for hotelCode.'], Response::HTTP_BAD_REQUEST); $this->logger->error('Hotel not found for hotelcode '.$query->hotelCode);
return $this->json(['error' => 'Hotel not found for hotelCode.'], Response::HTTP_BAD_REQUEST);
} }
try { try {
@@ -79,6 +85,10 @@ class ContingentController extends AbstractController
return $this->contingentsClient->getContingentCalendar($query->hotelCode, $query->dateFrom, $query->dateTo); return $this->contingentsClient->getContingentCalendar($query->hotelCode, $query->dateFrom, $query->dateTo);
}); });
} catch (BpnConnectException|InvalidArgumentException $e) { } catch (BpnConnectException|InvalidArgumentException $e) {
$this->logger->error('Failed to fetch contingent data', [
'error' => $e->getMessage(),
]);
return $this->json(['error' => 'Failed to fetch contingent data.'], Response::HTTP_BAD_GATEWAY); return $this->json(['error' => 'Failed to fetch contingent data.'], Response::HTTP_BAD_GATEWAY);
} }