2

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()));
        }

    }
}
1
  • 1
    Cleared the cache? Is there anything in the server logs? Commented Feb 7, 2014 at 20:37

1 Answer 1

2

Probably you're getting another exception in your exception listener, check symfony's log file.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.