I want create a JSON Exception with Symfny in a controller. I can create a HTML exception with
try {
// code here
} catch (InvalidArgumentException $e) {
throw $this->createNotFoundException($e->getMessage());
}
But it returns an HTML exception.
I try:
throw $this->createNotFoundException($e->getMessage())->setHeaders(['Content-Type'=>'application/json']);
But don't works