From 8c1eeb3a7a7469e90173373218fbf1ce30356eb6 Mon Sep 17 00:00:00 2001 From: TheFlow Date: Fri, 24 Oct 2025 12:13:21 +1300 Subject: [PATCH] fix(calendar): Add cache-busting and better error handling - Added cache: 'no-store' to prevent cached 500 errors - Enhanced error messages with status codes - Display detailed error messages to user - Log API response text for debugging - Helps diagnose mobile loading issues --- public/js/admin/calendar.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/public/js/admin/calendar.js b/public/js/admin/calendar.js index 418914d5..70a6059e 100644 --- a/public/js/admin/calendar.js +++ b/public/js/admin/calendar.js @@ -100,10 +100,15 @@ try { const token = localStorage.getItem('admin_token'); const response = await fetch('/api/calendar/stats', { + cache: 'no-store', headers: { 'Authorization': `Bearer ${token}` } }); - if (!response.ok) throw new Error('Failed to load stats'); + if (!response.ok) { + const errorText = await response.text(); + console.error('Stats API error:', response.status, errorText); + throw new Error(`Failed to load stats: ${response.status}`); + } const data = await response.json(); const stats = data.stats; @@ -116,7 +121,7 @@ } catch (error) { console.error('Error loading stats:', error); - showError('Failed to load statistics'); + showError('Failed to load statistics: ' + error.message); } } @@ -137,10 +142,15 @@ if (currentFilters.includeCompleted) params.append('includeCompleted', 'true'); const response = await fetch(`/api/calendar/tasks?${params}`, { + cache: 'no-store', headers: { 'Authorization': `Bearer ${token}` } }); - if (!response.ok) throw new Error('Failed to load tasks'); + if (!response.ok) { + const errorText = await response.text(); + console.error('Tasks API error:', response.status, errorText); + throw new Error(`Failed to load tasks: ${response.status}`); + } const data = await response.json(); allTasks = data.tasks; @@ -152,7 +162,8 @@ console.error('Error loading tasks:', error); tasksContainer.innerHTML = `
-

Failed to load tasks. Please try again.

+

Failed to load tasks: ${error.message}

+

Check console for details

`; }