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
This commit is contained in:
TheFlow 2025-10-24 12:13:21 +13:00
parent 3b584daa8d
commit 8c1eeb3a7a

View file

@ -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 = `
<div class="text-center py-12 text-red-600">
<p>Failed to load tasks. Please try again.</p>
<p>Failed to load tasks: ${error.message}</p>
<p class="text-sm mt-2">Check console for details</p>
</div>
`;
}