Skip to content

fix: validate Contributors API response schema#532

Merged
mehul-m-prajapati merged 2 commits into
GitMetricsLab:mainfrom
Tanayajadhav1:fix/contributors-response-validation
May 29, 2026
Merged

fix: validate Contributors API response schema#532
mehul-m-prajapati merged 2 commits into
GitMetricsLab:mainfrom
Tanayajadhav1:fix/contributors-response-validation

Conversation

@Tanayajadhav1
Copy link
Copy Markdown
Contributor

@Tanayajadhav1 Tanayajadhav1 commented May 26, 2026

Related Issue

Description

Implemented runtime validation and improved error handling for the ContributorsPage component to prevent unsafe GitHub API responses from causing runtime failures.

Changes made:

  • Added runtime type guard validation for Contributor[]

  • Added custom ContributorsError class for structured error handling

  • Added validation for all required contributor fields

  • Improved Axios error handling using axios.isAxiosError

  • Added handling for:

    • GitHub API rate limiting (403)
    • repository not found errors (404)
    • request timeout scenarios
    • malformed API responses
  • Prevented invalid API data from being assigned to state

  • Added improved fallback error UI and user feedback

This improves runtime safety, API resilience, and overall stability of the Contributors page.

How Has This Been Tested?

  • Verified TypeScript compilation passes successfully
  • Confirmed invalid response structures no longer reach rendering logic

Screenshots (if applicable)

N/A

Type of Change

  • Bug fix
  • New feature
  • Code style update
  • Breaking change
  • Documentation update

###Suggested Labels :
gssoc'26,gssoc:approved , type:fix , level:intermediate , quality:clean

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling and messaging on the Contributors page with specific notifications for different failure scenarios (rate limits, not found errors, timeouts, HTTP errors).
    • Added request timeout protection to prevent indefinite loading states.

Review Change Stack

Copilot AI review requested due to automatic review settings May 26, 2026 04:41
@netlify
Copy link
Copy Markdown

netlify Bot commented May 26, 2026

Deploy Preview for github-spy ready!

Name Link
🔨 Latest commit 61c37f9
🔍 Latest deploy log https://app.netlify.com/projects/github-spy/deploys/6a19c7ece1f2780008f7f076
😎 Deploy Preview https://deploy-preview-532--github-spy.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 26, 2026

Warning

Review limit reached

@mehul-m-prajapati, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 24 minutes and 9 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 32b9cb61-17f3-4592-80f4-d7a1778a7189

📥 Commits

Reviewing files that changed from the base of the PR and between dbc8d98 and 61c37f9.

📒 Files selected for processing (1)
  • src/pages/Contributors/Contributors.tsx
📝 Walkthrough

Walkthrough

The ContributorsPage component now validates GitHub API responses before using them. An isContributorArray type guard ensures the response is an array of valid contributors. The axios request adds a 10-second timeout and validates response shape. A new structured FetchError class captures multiple failure modes (rate-limit, 404, 408, timeout, generic HTTP), and the error UI renders conditional guidance via a MUI Alert based on error classification.

Changes

Contributors API Validation and Error Handling

Layer / File(s) Summary
Error types and response validation
src/pages/Contributors/Contributors.tsx
Introduces FetchError, ContributorsError classes, and isContributorArray type guard. The axios request adds a 10-second timeout and validates response.data before assigning to state. The catch handler classifies errors by failure mode (rate-limit, 404, 408, timeout, generic HTTP) and clears contributors on any error.
Conditional error UI rendering
src/pages/Contributors/Contributors.tsx
Replaces inline error string display with a structured MUI Alert that conditionally renders rate-limit guidance and specific error messages based on error.isRateLimited and error.statusCode (404 and 408).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A validation quest, so pure and true,
Types now guard what GitHub sends to you,
No more crashes when the data's wrong,
Errors flow through types, clear and strong,
Users see the truth—rate-limits, 404s, and more!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: validating the Contributors API response schema, which is the primary objective of this PR.
Description check ✅ Passed The description follows the template with all major sections completed: Related Issue, Description with detailed changes, How Has This Been Tested, Type of Change, and suggested labels.
Linked Issues check ✅ Passed The PR addresses all coding requirements from issue #506: validates HTTP response status, implements type guard validation for Contributor[], verifies required fields, handles error statuses (403, 404, 429) and timeouts, prevents invalid data assignment, and provides improved error UI.
Out of Scope Changes check ✅ Passed All changes are directly scoped to addressing issue #506 requirements: response validation, error handling, type guards, and improved error UI in the ContributorsPage component with no extraneous modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Improves the Contributors page’s resilience by adding response validation, richer error handling, and more informative error UI when the GitHub API request fails.

Changes:

  • Added a custom error type + structured FetchError state for richer error handling.
  • Added runtime validation to ensure the API returns a Contributor[] before rendering.
  • Expanded UI error messaging for rate limiting, 404, and timeout scenarios.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/pages/Contributors/Contributors.tsx
Comment thread src/pages/Contributors/Contributors.tsx
Comment thread src/pages/Contributors/Contributors.tsx
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/pages/Contributors/Contributors.tsx`:
- Around line 101-106: The error handling in the Contributors component
currently treats only HTTP 403 as a rate-limit; update the branch that checks
err.response?.status to treat 429 the same as 403 by checking for
(err.response?.status === 403 || err.response?.status === 429) and setting
fetchError.message to the rate-limit message, fetchError.isRateLimited = true,
and fetchError.statusCode to the actual status (403 or 429) for both occurrences
(the block using fetchError and the later similar branch around lines 112–114).
Ensure you adjust any message/context if you want to distinguish 429, otherwise
handle it identically to 403.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 72ff36c6-ae03-4e0d-bbbe-1d9df398d352

📥 Commits

Reviewing files that changed from the base of the PR and between 6c6bc3e and dbc8d98.

📒 Files selected for processing (1)
  • src/pages/Contributors/Contributors.tsx

Comment thread src/pages/Contributors/Contributors.tsx
@Tanayajadhav1
Copy link
Copy Markdown
Contributor Author

hi @mehul-m-prajapati please review this pr whenever possible!

@mehul-m-prajapati
Copy link
Copy Markdown
Collaborator

Ok @Tanayajadhav1

@mehul-m-prajapati mehul-m-prajapati merged commit f09387a into GitMetricsLab:main May 29, 2026
5 of 6 checks passed
@github-actions
Copy link
Copy Markdown

🎉🎉 Thank you for your contribution! Your PR #532 has been merged! 🎉🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 Bug Report: Contributors API Response Not Type-Validated

3 participants