Tambah logging detail untuk debug Failed to fetch di lokal

This commit is contained in:
mwpn
2025-12-19 05:22:27 +07:00
parent 7d1e27fb0b
commit 801ea1bfcd
2 changed files with 35 additions and 2 deletions

View File

@@ -85,10 +85,18 @@
submitBtn.textContent = 'Memproses...';
try {
// Import config untuk cek API Base URL
const { API_CONFIG } = await import('./dashboard/js/config.js');
console.log('[Login] API Base URL:', API_CONFIG.BASE_URL);
const {
apiLogin
} = await import('./dashboard/js/api.js');
console.log('[Login] Attempting login for:', username);
const response = await apiLogin(username, password);
console.log('[Login] Response:', response);
if (response.token) {
Auth.saveToken(response.token);
Auth.saveUser(response.user);
@@ -98,7 +106,16 @@
throw new Error('Response tidak berisi token.');
}
} catch (error) {
errorDiv.textContent = error.message || 'Login gagal. Silakan coba lagi.';
console.error('[Login] Error:', error);
let errorMessage = error.message || 'Login gagal. Silakan coba lagi.';
// Tambahkan info lebih detail untuk debugging
if (error.message === 'Failed to fetch' || error.message.includes('fetch')) {
errorMessage = 'Gagal terhubung ke server API. Pastikan backend API sudah running di ' +
(await import('./dashboard/js/config.js')).then(m => m.API_CONFIG.BASE_URL).catch(() => 'http://localhost:8000');
}
errorDiv.textContent = errorMessage;
errorDiv.classList.remove('hidden');
submitBtn.disabled = false;
submitBtn.textContent = 'Login';