feat: improved error handling of xml parsers and loaders

This commit is contained in:
Björn Fromme
2026-03-16 11:59:10 +01:00
parent 0f6b73340e
commit 4f02529b15
9 changed files with 257 additions and 42 deletions
@@ -0,0 +1,60 @@
<?php
declare(strict_types=1);
namespace App\Controller\Booking;
use App\Exception\HotelNotFoundException;
use App\Exception\HotelNotInTravelException;
use App\Exception\NoRoomsAvailableException;
use App\Exception\TravelNotFoundException;
use App\Service\BookingService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
/**
* Handles the initialization of new booking sessions.
*
* This controller provides a clean entry point for starting new booking flows
* without requiring random UID parameters. It creates fresh booking sessions
* and redirects to the first step of the booking process.
*/
class CreateInitController extends AbstractController
{
public function __construct(
private readonly BookingService $bookingService,
) {
}
/**
* Initializes a fresh booking session and redirects to step 1.
*
* This endpoint provides a clean way to start the booking flow with just
* dateId and hotelId parameters. It clears any existing booking session
* and creates a fresh BookingCreateDto before redirecting to step 1.
*/
#[Route('/bookings/create/{dateId}/{hotelId}', name: 'app_booking_create_init', requirements: ['dateId' => '\d+', 'hotelId' => '\d+'])]
public function init(Request $request, int $dateId, int $hotelId): Response
{
try {
// Clear any existing booking session to ensure fresh start
$this->bookingService->clearBookingSession($request);
// Create fresh booking session with the provided parameters
$this->bookingService->startFreshBooking($request, $dateId, $hotelId);
// Redirect to step 1 of the booking flow
return $this->redirectToRoute('app_booking_create_step_1');
} catch (TravelNotFoundException $e) {
throw $this->createNotFoundException(sprintf('Travel not found for date ID %d', $dateId));
} catch (HotelNotFoundException $e) {
throw $this->createNotFoundException(sprintf('Hotel not found for hotel ID %d', $hotelId));
} catch (HotelNotInTravelException $e) {
throw $this->createNotFoundException(sprintf('Hotel ID %d is not available for travel ID %d', $hotelId, $dateId));
} catch (NoRoomsAvailableException $e) {
throw $this->createNotFoundException('No rooms available for this travel.');
}
}
}
@@ -36,8 +36,6 @@ class CreateStep1Controller extends AbstractController
try {
$bookingCreateDto = $this->bookingService->getOrCreateBookingCreateDto($request);
} catch (NoRoomsAvailableException $e) {
$this->addFlash('error', 'Leider sind für diese Reise aktuell keine Zimmer verfügbar.');
// TODO: Redirect to travel listing or hotel details page
throw $this->createNotFoundException('No rooms available for this travel.');
}
@@ -93,8 +91,7 @@ class CreateStep1Controller extends AbstractController
try {
$bookingCreateDto = $this->bookingService->getOrCreateBookingCreateDto($request);
} catch (NoRoomsAvailableException $e) {
// For HTMX requests, return a simple error message
return new Response('<div class="text-red-700 p-4">Keine Zimmer verfügbar</div>', 400);
throw $this->createNotFoundException('No rooms available for this travel.');
}
// Process the form to update the DTO with the latest room selection