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

Loading…
Cancel
Save