2

I have an event listener hooked to kernel.request event. In the onKernel request method i am making some validations based on the subdomain. If this validations fail I want to throw some exception like AccessDenied or something.

The problem is when I throw the exception it shows a blank page instead of my custom error page.

If I check my prod.log file I get the following info:

[2013-06-06 11:08:38] request.ERROR: Exception thrown when handling an exception (Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException: This route needs to be accessed with a subdomain) [] []
[2013-06-06 11:16:32] request.ERROR: Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException: "This route needs to be accessed with a subdomain" at (...) line 86 [] [] 

What i am missing? Thank you for your help

2
  • you're in dev mode and have enabled error reporting in your php.ini ? It's strange you have a blank page. Commented Jun 6, 2013 at 10:56
  • no,in dev environment it shows the errors. Thats not the question. I want to customize the error pages that are showing in production like when an exception is thrown, show something like "An error ocurred in the application". Commented Jun 6, 2013 at 11:11

1 Answer 1

4

Exceptions are not catched during kernel.request events. You can return a response instead:

class SubdomainSubscriber implements EventSubscriberInterface
{

    public static function getSubscribedEvents()
    {
        return [
            'kernel.request' => 'onRequest',
        ];
    }

    public function onRequest(GetResponseEvent $event)
    {
        if (!$subdomainValid) {
            $event->setResponse(new Response('Invalid subdomain!', 403));
        }
    }
}

Although this example is an EventSubscriber it works with a listener, too.

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.