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:
@@ -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(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user