I have a 404 handler in symfony2 which is an EventListener.
With certain 404's, I do a redirect, which works great. To the browser, no 404 is thrown.
new RedirectResponse( $newURL );
That line basically replaces the 404 status code with a 200.
In other cases though, I want to return some content instead, not a 404 message, but some replacement data. Something like this:
$response = new Response( $returnJSONMessage );
$response->headers->set( 'Content-Type', 'application/json' );
$response->setStatusCode(200);
Code wise, this is fine, but it doesn't stop the 404 being returned. I am guessing because it sits within this:
$event->setResponse( $theResponse );
Which is of type GetResponseForExceptionEvent.
What do I need to call, to get it to return my data as a 200 instead of a 404. In the same way that RedirectResponse seems to. I tried:
$event->stopPropagation();
But it is a bit after the fact. It seems anything within $event->setResponse which isn't a RedirectResponse gets labelled a 404 in this case.
Any ideas?