public function onCKFinderError(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     $exceptionCode = $exception->getCode() ?: Error::UNKNOWN;
     $replacements = array();
     $httpStatusCode = 200;
     if ($exception instanceof CKFinderException) {
         $replacements = $exception->getParameters();
         $httpStatusCode = $exception->getHttpStatusCode();
     }
     $message = $exceptionCode === Error::CUSTOM_ERROR ? $exception->getMessage() : $this->translator->translateErrorMessage($exceptionCode, $replacements);
     $response = JsonResponse::create()->withError($exceptionCode, $message);
     $event->setException(new HttpException($httpStatusCode));
     $event->setResponse($response);
     if ($this->debug && $this->logger) {
         $this->logger->error($exception);
     }
     if (filter_var(ini_get('display_errors'), FILTER_VALIDATE_BOOLEAN)) {
         throw $exception;
     }
 }
 /**
  * Create response
  *
  * @param GetResponseForControllerResultEvent $event
  */
 public function createResponse(GetResponseForControllerResultEvent $event)
 {
     /* @var $dispatcher EventDispatcher */
     $dispatcher = $this['dispatcher'];
     $commandName = $event->getRequest()->get('command');
     $eventName = CKFinderEvent::CREATE_RESPONSE_PREFIX . lcfirst($commandName);
     $dispatcher->dispatch($eventName, $event);
     $controllerResult = $event->getControllerResult();
     $event->setResponse(JsonResponse::create($controllerResult));
 }