I have done some custom exception listener, so in database in table I have got old url which is now 404 error and another url to which user should be redirected when it will get to the old url. The problem is that everything is working fine on DEV environment but I have got problem to get it working on PROD environment (it is throwing 503 Service Unavailable Error).
Does anyone may know what can be wrong?
services.yml:
services:
coupons.exception.action_listener:
class: Coupons\WebBundle\EventListener\ExceptionListener
arguments: [@service_container, @templating]
tags:
- { name: kernel.event_listener, event: kernel.exception, method: onKernelException }
ExecptionListener:
namespace Coupons\WebBundle\EventListener;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Bundle\TwigBundle\TwigEngine;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
class ExceptionListener
{
/**
* @var ContainerInterface
*/
protected $container;
/**
* @var TwigEngine
*/
protected $templating;
/**
* @param ContainerInterface $container
*/
public function __construct(ContainerInterface $container, TwigEngine $templating){
// assign value(s)
$this->container = $container;
$this->templating = $templating;
}
/**
*
* @param GetResponseForExceptionEvent $event
*/
public function onKernelException(GetResponseForExceptionEvent $event)
{
// get exception
$exception = $event->getException();
// get path
$path = $event->getRequest()->getPathInfo();
$url = $event->getRequest()->getUri();
$repository = $this->container->get('doctrine')->getRepository('CouponsWebBundle:SeoNotFound');
$seonotfound = $repository->createQueryBuilder('s')
->where('s.urlFrom LIKE :url')
->andWhere('s.status = 1')
->setParameter('url', $url.'%')
->getQuery()
->getOneOrNullResult();
if($seonotfound != NULL){
$event->setResponse(new RedirectResponse($seonotfound->getUrlTo(),$seonotfound->getRedirectType()));
}
}
}