'onKernelException', ]; } public function onKernelException(ExceptionEvent $event): void { if ($this->kernel->getEnvironment() === 'dev') { return; } $exception = $event->getThrowable(); $statusCode = $exception instanceof HttpExceptionInterface ? $exception->getStatusCode() : 500; $message = $exception->getMessage(); $data = [ '@context' => '/contexts/Error', '@type' => 'hydra:Error', 'hydra:title' => 'An error occurred', 'hydra:description' => $message, ]; $response = new JsonResponse($data, $statusCode); $event->setResponse($response); } }