Use symfony ExceptionHandler object to handle errors (only in test mode)

- If a database error exists a more informative debug appears.
- tag "@throws \Doctrine\DBAL\DBALException" will be not needed
pull/2472/head
jmontoyaa 8 years ago
parent 05debb857e
commit 8a14be221b
  1. 18
      main/inc/lib/database.lib.php

@ -1,6 +1,7 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
use Symfony\Component\Debug\ExceptionHandler;
use Doctrine\Common\Annotations\AnnotationRegistry; use Doctrine\Common\Annotations\AnnotationRegistry;
use Doctrine\DBAL\Connection; use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver\Statement; use Doctrine\DBAL\Driver\Statement;
@ -377,19 +378,22 @@ class Database
/** /**
* @param string $query * @param string $query
* *
* @throws \Doctrine\DBAL\DBALException
*
* @return Statement * @return Statement
*/ */
public static function query($query) public static function query($query)
{ {
$connection = self::getManager()->getConnection(); $connection = self::getManager()->getConnection();
if (api_get_setting('server_type') == 'test') { $result = null;
try {
$result = $connection->executeQuery($query); $result = $connection->executeQuery($query);
} else { } catch (Exception $e) {
try { $debug = api_get_setting('server_type') == 'test';
$result = $connection->executeQuery($query); if ($debug) {
} catch (Exception $e) { // We use Symfony exception handler for better error information
$handler = new ExceptionHandler();
$handler->handle($e);
exit;
} else {
error_log($e->getMessage()); error_log($e->getMessage());
api_not_allowed(false, get_lang('GeneralError')); api_not_allowed(false, get_lang('GeneralError'));
} }

Loading…
Cancel
Save