fix: return proper response for stale participant edit urls
This commit is contained in:
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Exception;
|
||||||
|
|
||||||
|
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exception thrown when attempting to access a participant that does not exist.
|
||||||
|
*
|
||||||
|
* This is used for stale or tampered participant index URLs in booking flows.
|
||||||
|
*/
|
||||||
|
class ParticipantNotFoundException extends HttpException
|
||||||
|
{
|
||||||
|
public function __construct(int $index, ?\Throwable $previous = null)
|
||||||
|
{
|
||||||
|
$message = sprintf('Participant at index %d does not exist', $index);
|
||||||
|
|
||||||
|
parent::__construct(404, $message, $previous);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace App\Service;
|
namespace App\Service;
|
||||||
|
|
||||||
|
use App\Exception\ParticipantNotFoundException;
|
||||||
use App\Form\Model\BookingDto;
|
use App\Form\Model\BookingDto;
|
||||||
use App\Form\Model\ParticipantDto;
|
use App\Form\Model\ParticipantDto;
|
||||||
use App\Form\Model\ParticipantEditDto;
|
use App\Form\Model\ParticipantEditDto;
|
||||||
@@ -24,7 +25,7 @@ class ParticipantFormSupportService
|
|||||||
$participant = $bookingDto->participants[$index] ?? null;
|
$participant = $bookingDto->participants[$index] ?? null;
|
||||||
|
|
||||||
if (null === $participant) {
|
if (null === $participant) {
|
||||||
throw new \InvalidArgumentException(sprintf('Participant at index %d does not exist', $index));
|
throw new ParticipantNotFoundException($index);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $participant;
|
return $participant;
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ namespace App\Tests\Service;
|
|||||||
|
|
||||||
use App\BusProNet\Model\Booking;
|
use App\BusProNet\Model\Booking;
|
||||||
use App\BusProNet\Model\Travel;
|
use App\BusProNet\Model\Travel;
|
||||||
|
use App\Exception\ParticipantNotFoundException;
|
||||||
use App\Form\Model\BookingDto;
|
use App\Form\Model\BookingDto;
|
||||||
use App\Form\Model\ParticipantDto;
|
use App\Form\Model\ParticipantDto;
|
||||||
use App\Service\ParticipantFormSupportService;
|
use App\Service\ParticipantFormSupportService;
|
||||||
@@ -19,7 +20,7 @@ class ParticipantFormSupportServiceTest extends TestCase
|
|||||||
$service = $this->createService();
|
$service = $this->createService();
|
||||||
$bookingDto = $this->createBookingDto();
|
$bookingDto = $this->createBookingDto();
|
||||||
|
|
||||||
$this->expectException(\InvalidArgumentException::class);
|
$this->expectException(ParticipantNotFoundException::class);
|
||||||
$this->expectExceptionMessage('Participant at index 2 does not exist');
|
$this->expectExceptionMessage('Participant at index 2 does not exist');
|
||||||
|
|
||||||
$service->ensureParticipantExists($bookingDto, 2);
|
$service->ensureParticipantExists($bookingDto, 2);
|
||||||
|
|||||||
Reference in New Issue
Block a user