i may going wrong way, have onkernelrequest event setup picks current domain (multi site on single application), queries cache/db , stores in service use other controllers/services. works perfectly.
now if domain isn't found, i'd throw 404 error. i'd following in controller:
throw new notfoundhttpexception('not found!');
but results in uncaught exception in production, i'm assuming due priority of event (31).
php fatal error: uncaught exception 'symfony\component\httpkernel\exception\notfoundhttpexception' message 'not found!'
my current code (with logic removed clarity), note use jmsdiextrabundle configure services.
/** * @service */ class currentdomainlistener { /** * @observe("kernel.request", priority=31) */ public function onkernelrequest(getresponseevent $event) { // find domain in cache/database... if (!$domain) { throw new notfoundhttpexception('not found!'); } // store domain in service... } }
my question best way display 404 error when domain doesn't exist?
you return 404 response instead of throwing exception:
public function onkernelrequest(getresponseevent $event) { // find domain in cache/database... if (!$domain) { $event->setresponse(new response('not found!', 404)); } // store domain in service... }
Comments
Post a Comment