Skip to content

Commit c2ba78d

Browse files
simonwclaude
andauthored
Handle 401 errors by showing authenticate button again (#102)
When the GitHub API returns a 401 (unauthorized) or 403 (forbidden) status, the tool now: - Removes the invalid token from localStorage - Shows the authenticate button again - Displays an error message prompting the user to re-authenticate This improves the user experience when tokens expire or become invalid. Co-authored-by: Claude <noreply@anthropic.com>
1 parent d1a1d6c commit c2ba78d

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

github-ratelimit.html

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,13 @@ <h1>GitHub Rate Limit Checker</h1>
354354
});
355355

356356
if (!response.ok) {
357-
throw new Error('Failed to fetch rate limit');
357+
if (response.status === 401 || response.status === 403) {
358+
localStorage.removeItem('GITHUB_TOKEN');
359+
checkGithubAuth();
360+
resultsDiv.innerHTML = '<div class="error">Authentication failed. Please authenticate again.</div>';
361+
return;
362+
}
363+
throw new Error(`Failed to fetch rate limit: ${response.status} ${response.statusText}`);
358364
}
359365

360366
const data = await response.json();
@@ -424,14 +430,7 @@ <h1>GitHub Rate Limit Checker</h1>
424430

425431
} catch (error) {
426432
console.error('Rate limit check failed:', error);
427-
428-
if (error.message.includes('401') || error.message.includes('403')) {
429-
localStorage.removeItem('GITHUB_TOKEN');
430-
checkGithubAuth();
431-
resultsDiv.innerHTML = '<div class="error">Authentication failed. Please authenticate again.</div>';
432-
} else {
433-
resultsDiv.innerHTML = `<div class="error">Failed to check rate limit: ${error.message}</div>`;
434-
}
433+
resultsDiv.innerHTML = `<div class="error">Failed to check rate limit: ${error.message}</div>`;
435434
} finally {
436435
checkRateLimitBtn.disabled = false;
437436
checkRateLimitBtn.textContent = 'Check Rate Limit';

0 commit comments

Comments
 (0)