debug: add detailed logging to trace history loading

This commit is contained in:
Christian Vidal Wolf
2026-04-23 18:51:07 +02:00
parent 0eeeeb480c
commit be2adbfe68
2 changed files with 19 additions and 10 deletions
+13 -8
View File
@@ -161,26 +161,31 @@ export async function saveHistoryEntry(
export async function getHistory(): Promise<HistoryEntry[]> {
try {
const response = await safeFetch(
`${SUPABASE_URL}/rest/v1/products_history?select=*&order=changed_at.desc&limit=500`,
{ cache: 'no-store' }
);
const url = `${SUPABASE_URL}/rest/v1/products_history?select=*&order=changed_at.desc&limit=500`;
console.log('[getHistory] Fetching from:', url);
console.log('[getHistory] Session:', !!getStoredSession(), 'ANON_KEY available:', !!SUPABASE_ANON_KEY);
const response = await safeFetch(url, { cache: 'no-store' });
console.log('[getHistory] Response status:', response.status);
console.log('[getHistory] Response ok:', response.ok);
if (!response.ok) {
const err = await response.text();
const errText = await response.text();
console.error('[getHistory] Error response:', errText);
return [{
id: -1,
product_id: 'ERROR',
article_name: `Failed: ${response.status} ${err}`,
article_name: `Failed: ${response.status} ${errText.substring(0, 200)}`,
old_data: [],
new_data: [],
changed_at: new Date().toISOString(),
changed_by: 'system'
}];
}
return await response.json();
const data = await response.json();
console.log('[getHistory] Received entries:', Array.isArray(data) ? data.length : data);
return data;
} catch (error: any) {
console.error('Error fetching history:', error);
console.error('[getHistory] Exception:', error.message);
return [{
id: -2,
product_id: 'EXCEPTION',