Skip to content

Implement comprehensive error handling for GitHub API authentication and rate limiting - #67

Merged
ModelEarth merged 1 commit into
ModelEarth:mainfrom
shashank11yadav:main
Oct 17, 2025
Merged

ModelEarth merged 1 commit into
ModelEarth:mainfrom
shashank11yadav:main

Conversation

@shashank11yadav

Copy link
Copy Markdown
Contributor

Verify changes here - https://shashank11yadav.github.io/projects/hub

This commit adds robust error handling for two critical API error scenarios: 401 Unauthorized (invalid tokens) and 403 Forbidden (rate limit exceeded).

Key improvements:

  1. Token Validation on Save:

    • Added ASCII character validation to prevent non-ISO-8859-1 characters
    • Shows clear error message when invalid characters are detected
    • Prevents HTTP header errors from malformed tokens
  2. Automatic Invalid Token Recovery:

    • Detects 401 Unauthorized responses in getRepositoryIssueCount()
    • Automatically clears invalid token from localStorage
    • Retries failed requests without authentication
    • Updates UI to reflect cleared token state
    • Seamlessly falls back to 60 requests/hour limit
  3. Automatic Invalid Token Recovery in apiRequestWithMetadata():

    • Added retry logic for 401 errors
    • Clears invalid token and retries without authentication
    • Updates rate limit display for unauthenticated access
    • Returns data successfully on retry
    • Shows user notification about fallback to unauthenticated mode
  4. Rate Limit Error Handling:

    • Detects 403 Forbidden responses when rate limit is exceeded
    • Extracts reset time from response headers
    • Shows user-friendly error message with reset time
    • Updates rate limit display with remaining requests and reset time
    • Prevents duplicate error messages with warning flags
  5. Warning Flag Management:

    • Added invalidTokenWarningShown flag to prevent duplicate warnings
    • Added rateLimitWarningShown flag to prevent duplicate warnings
    • Resets flags when new token is saved or cache is cleared
    • Ensures users see clear feedback without message spam
  6. UI Improvements:

    • Added null checks for DOM elements to prevent crashes
    • Updates token input UI when token is cleared
    • Shows clear rate limit information in header
    • Provides actionable feedback to users
  7. Cache Clear Enhancement:

    • Resets all warning flags on cache clear
    • Allows fresh error messages after clearing cache
    • Ensures proper error recovery flow

Technical changes:

  • Modified saveToken() to validate token format before saving
  • Enhanced getRepositoryIssueCount() with 401 and 403 error handling
  • Enhanced apiRequestWithMetadata() with automatic retry on 401
  • Added warning flags to constructor initialization
  • Updated clearAllCache() to reset warning flags
  • Added updateTokenUI() call after clearing invalid tokens

User benefits:

  • No manual intervention needed when token becomes invalid
  • Automatic fallback to unauthenticated access (60 requests/hour)
  • Clear feedback about rate limits and reset times
  • Seamless recovery when valid token is added
  • Protection against malformed tokens causing API errors

…and rate limiting

This commit adds robust error handling for two critical API error scenarios:
401 Unauthorized (invalid tokens) and 403 Forbidden (rate limit exceeded).

Key improvements:

1. Token Validation on Save:
   - Added ASCII character validation to prevent non-ISO-8859-1 characters
   - Shows clear error message when invalid characters are detected
   - Prevents HTTP header errors from malformed tokens

2. Automatic Invalid Token Recovery:
   - Detects 401 Unauthorized responses in getRepositoryIssueCount()
   - Automatically clears invalid token from localStorage
   - Retries failed requests without authentication
   - Updates UI to reflect cleared token state
   - Seamlessly falls back to 60 requests/hour limit

3. Automatic Invalid Token Recovery in apiRequestWithMetadata():
   - Added retry logic for 401 errors
   - Clears invalid token and retries without authentication
   - Updates rate limit display for unauthenticated access
   - Returns data successfully on retry
   - Shows user notification about fallback to unauthenticated mode

4. Rate Limit Error Handling:
   - Detects 403 Forbidden responses when rate limit is exceeded
   - Extracts reset time from response headers
   - Shows user-friendly error message with reset time
   - Updates rate limit display with remaining requests and reset time
   - Prevents duplicate error messages with warning flags

5. Warning Flag Management:
   - Added invalidTokenWarningShown flag to prevent duplicate warnings
   - Added rateLimitWarningShown flag to prevent duplicate warnings
   - Resets flags when new token is saved or cache is cleared
   - Ensures users see clear feedback without message spam

6. UI Improvements:
   - Added null checks for DOM elements to prevent crashes
   - Updates token input UI when token is cleared
   - Shows clear rate limit information in header
   - Provides actionable feedback to users

7. Cache Clear Enhancement:
   - Resets all warning flags on cache clear
   - Allows fresh error messages after clearing cache
   - Ensures proper error recovery flow

Technical changes:
- Modified saveToken() to validate token format before saving
- Enhanced getRepositoryIssueCount() with 401 and 403 error handling
- Enhanced apiRequestWithMetadata() with automatic retry on 401
- Added warning flags to constructor initialization
- Updated clearAllCache() to reset warning flags
- Added updateTokenUI() call after clearing invalid tokens

User benefits:
- No manual intervention needed when token becomes invalid
- Automatic fallback to unauthenticated access (60 requests/hour)
- Clear feedback about rate limits and reset times
- Seamless recovery when valid token is added
- Protection against malformed tokens causing API errors
@ModelEarth
ModelEarth merged commit ebd8991 into ModelEarth:main Oct 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants