From 7b2056bafcae512f144dd27ad3c69e56bec523a8 Mon Sep 17 00:00:00 2001 From: "Joseph.Rawlings" Date: Wed, 3 Dec 2025 16:22:11 -0500 Subject: [PATCH] feat: enhance error handling in statistics retrieval by providing detailed messages for missing current and historical data, improving user feedback and experience --- .../Servers/Proxmox/Livewire/Statistics.php | 22 +++++++++++++--- .../Proxmox/views/statistics.blade.php | 25 ++++++++++++++++++- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/extensions/Servers/Proxmox/Livewire/Statistics.php b/extensions/Servers/Proxmox/Livewire/Statistics.php index 6b5255b2e..53cdfe8a8 100644 --- a/extensions/Servers/Proxmox/Livewire/Statistics.php +++ b/extensions/Servers/Proxmox/Livewire/Statistics.php @@ -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(), + ]; } } diff --git a/extensions/Servers/Proxmox/views/statistics.blade.php b/extensions/Servers/Proxmox/views/statistics.blade.php index 2e2b9f031..88fb7c06a 100644 --- a/extensions/Servers/Proxmox/views/statistics.blade.php +++ b/extensions/Servers/Proxmox/views/statistics.blade.php @@ -1738,7 +1738,7 @@ - @if($historicalComparison) + @if($historicalComparison && !isset($historicalComparison['error'])) @@ -1900,6 +1900,29 @@ + @elseif($historicalComparison && isset($historicalComparison['error'])) +
+
+
+
+ +
+
+

{{ $historicalComparison['message'] }}

+ @if(isset($historicalComparison['total_stats'])) +

+ Total statistics in database: {{ $historicalComparison['total_stats'] }} + @if($historicalComparison['total_stats'] == 0) + - Statistics are collected automatically every hour. You can also create manual statistics using the "Create Statistics" button above. + @elseif($historicalComparison['total_stats'] < 2) + - At least 2 statistics are needed for comparison. Wait for more data to be collected or create a manual statistic. + @endif +

+ @endif +
+
+
+
@else