← Back to Demo Hub
Test #7API & Data Fetching

Unhandled 401 Unauthorized

Auth token expired during user session, but the error isn't handled properly.

📋 Demo Instructions

  1. Click the "Trigger Error" button below
  2. Open browser console (F12) to see the error
  3. Wait 5-10 seconds for the error to be captured
  4. Go to Dashboard → Performance Monitoring
  5. Click "Fix with Carla" on the error
  6. Review the generated PR
🌍 Real-World Scenario
User's JWT token expires while they're actively using the app. API returns 401, but frontend doesn't detect it and tries to use the error response as valid data.
✅ Expected Fix
Check response.status for 401 errors and redirect to login. Also check response.ok before processing data.
Fix Confidence:MEDIUM

💻 Buggy Code

// Buggy Code
const response = await fetch('/api/user/profile', {
  headers: { Authorization: 'Bearer expired_token' }
});
const data = await response.json();
console.log(data.user.email);
// TypeError when 401 returns { error: 'Unauthorized' }

🔴 Error Log

Waiting for error to be triggered...