Add error handling to default subpanel statistic

- Check if queries is empty
-- Return error statistic
-- Add logging
This commit is contained in:
Clemente Raposo 2021-03-11 11:15:48 +00:00 committed by Dillon-Brown
parent 4bda1b7771
commit cc79d2e375

View file

@ -5,13 +5,20 @@ namespace App\Legacy\Statistics;
use App\Entity\Statistic; use App\Entity\Statistic;
use App\Legacy\Data\PresetDataHandlers\SubpanelDataQueryHandler; use App\Legacy\Data\PresetDataHandlers\SubpanelDataQueryHandler;
use App\Service\StatisticsProviderInterface; use App\Service\StatisticsProviderInterface;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;
class SubpanelDefault extends SubpanelDataQueryHandler implements StatisticsProviderInterface class SubpanelDefault extends SubpanelDataQueryHandler implements StatisticsProviderInterface, LoggerAwareInterface
{ {
use StatisticsHandlingTrait; use StatisticsHandlingTrait;
public const KEY = 'default'; public const KEY = 'default';
/**
* @var LoggerInterface
*/
protected $logger;
/** /**
* @inheritDoc * @inheritDoc
*/ */
@ -38,6 +45,12 @@ class SubpanelDefault extends SubpanelDataQueryHandler implements StatisticsProv
$queries = $this->getQueries($module, $id, $subpanel); $queries = $this->getQueries($module, $id, $subpanel);
if (empty($queries)) {
$this->logger->error('default-statistic: No queries found.', ['query' => $query]);
return $this->getErrorResponse(self::KEY);
}
$parts = $queries[0]; $parts = $queries[0];
$parts['select'] = 'SELECT COUNT(*) as value'; $parts['select'] = 'SELECT COUNT(*) as value';
@ -50,4 +63,12 @@ class SubpanelDefault extends SubpanelDataQueryHandler implements StatisticsProv
return $statistic; return $statistic;
} }
/**
* @inheritDoc
*/
public function setLogger(LoggerInterface $logger)
{
$this->logger = $logger;
}
} }