/**
* Handle errors thrown in the application.
*
* @param GetResponseForExceptionEvent $event
*/
public function onKernelException(GetResponseForExceptionEvent $event)
{
if ($this->isProfilerRequest($event->getRequest())) {
return;
}
$exception = $event->getException();
$message = $exception->getMessage();
$statusCode = Response::HTTP_INTERNAL_SERVER_ERROR;
if ($exception instanceof HttpExceptionInterface) {
$statusCode = $exception->getStatusCode();
}
// Log the error message
$level = LogLevel::CRITICAL;
if ($exception instanceof HttpExceptionInterface && $exception->getStatusCode() < 500) {
$level = LogLevel::WARNING;
}
$this->logger->log($level, $message, ['event' => 'exception', 'exception' => $exception]);
// Get and send the response
if ($this->isJsonRequest($event->getRequest())) {
$response = new JsonResponse(['success' => false, 'errorType' => get_class($exception), 'code' => $statusCode, 'message' => $message]);
} elseif ($this->config->get('general/debug_error_use_symfony')) {
return null;
} else {
$response = $this->exceptionController->kernelException($event);
}
$response->setStatusCode($statusCode);
$event->setResponse($response);
}