feat: enhance error handling in statistics retrieval by providing detailed messages for missing current and historical data, improving user feedback and experience

This commit is contained in:
2025-12-03 16:22:11 -05:00
parent 99abb8594c
commit 7b2056bafc
2 changed files with 43 additions and 4 deletions

View File

@@ -1309,8 +1309,21 @@ class Statistics extends Component
// Get historical period statistics with its previous record
$historicalStats = $this->getStatisticsForPeriodWithPrevious($this->historicalPeriod, $this->historicalCustomDate);
if (!$currentStats || !$historicalStats || !$currentStats['stat'] || !$historicalStats['stat']) {
return null;
// Check if we have both current and historical stats
if (!$currentStats || !$currentStats['stat']) {
return [
'error' => 'current',
'message' => 'No statistics found for the selected current period (' . $this->currentPeriod . ').',
'total_stats' => ServerStatistics::where('server_id', $this->server->id)->count(),
];
}
if (!$historicalStats || !$historicalStats['stat']) {
return [
'error' => 'historical',
'message' => 'No statistics found for the selected historical period (' . $this->historicalPeriod . '). Try selecting a different time period.',
'total_stats' => ServerStatistics::where('server_id', $this->server->id)->count(),
];
}
$current = $currentStats['stat'];
@@ -1336,7 +1349,10 @@ class Statistics extends Component
return $comparison;
} catch (\Throwable $e) {
\Log::error('Error getting historical comparison: ' . $e->getMessage());
return null;
return [
'error' => 'exception',
'message' => 'An error occurred while loading comparison data: ' . $e->getMessage(),
];
}
}