/**
  * @param GetResponseForExceptionEvent $event
  *
  * @return void
  * @author Michaël VEROUX
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if (!$event->getException() instanceof AccessDeniedException) {
         $exception = null;
         try {
             parent::onKernelException($event);
         } catch (\Exception $e) {
             $exception = $e;
         }
         if (!$exception instanceof HttpExceptionInterface && !$event->getException() instanceof HttpExceptionInterface && 'prod' === $this->mode) {
             $this->loggerDb->error($event->getException()->getMessage(), array('exception' => $event->getException()));
             if ($this->flashBag) {
                 if (null === $this->lastError->getId()) {
                     $this->flashBag->add('error', 'Une erreur est survenue');
                 } else {
                     $this->flashBag->add('error', sprintf('Une erreur est survenue #%s', $this->lastError->getId()));
                 }
             }
         }
     }
 }
Пример #2
0
 /**
  * Writes the record down to the log of the implementing handler
  *
  * @param  array $record
  *
  * @return void
  */
 protected function write(array $record)
 {
     $this->record = $record;
     $error = new Error();
     $error->setMessage($this->getFromRecord('message'));
     $error->setFile($this->getFile());
     $error->setLine($this->getLine());
     $error->setTrace($this->getTrace());
     $error->setType($this->getType());
     $error->setCode($this->getCode());
     $error->setUri($this->getFromRecordExtra('uri'));
     $error->setRoute($this->getFromRecordExtra('route'));
     $error->setController($this->getFromRecordExtra('controller'));
     $error->setUserAgent($this->getFromRecordExtra('userAgent'));
     $error->setUserContext($this->getFromRecordExtra('userContext'));
     $error->setUser($this->getFromRecordExtra('user'));
     if (!$this->entityManager->isOpen()) {
         $this->entityManager = $this->entityManager->create($this->entityManager->getConnection(), $this->entityManager->getConfiguration());
     }
     $this->entityManager->persist($error);
     $this->entityManager->flush($error);
     $this->lastError->setId($error->getId());
 }