API Platform: How to add XDebug breakpoint on 500 error
10 May 2024 (Updated 10 May 2024)
Ensure you’ve installed XDebug and then add a file at src/EventSubscriber/ApiExceptionListener.php
:
<?php
declare(strict_types=1);
namespace App\EventSubscriber;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpKernel\KernelEvents;
#[AsEventListener(event: KernelEvents::EXCEPTION, method: 'onKernelException')]
final readonly class ApiExceptionListener
{
public function onKernelException(ExceptionEvent $event): void
{
$exception = $event->getThrowable();
$foo = 'bar'; // Any line will do. This is just so that we can set the breakpoint here
}
}
Set the breakpoint here:
Tagged:
API Platform
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment