Skip to content

Bug: Contributor profile page crashes when GitHub API fails or invalid username is used #461

@mayurigade-hub

Description

@mayurigade-hub

What is happening?

The /contributor/:username page is not properly handling failed GitHub API responses.

Because of this, two related issues happen:

1. Page crashes when GitHub rate limit is exceeded

When GitHub blocks too many requests, the API returns an error response instead of PR data.

Current code directly does:

setPRs(prsData.items);

If items is missing, the page crashes with a TypeError.


2. Invalid usernames show a broken page

When visiting a non-existent GitHub username, GitHub returns a 404 response.

But the code still stores the error object as profile data instead of showing a proper error message.

As a result:

  • empty avatar
  • broken profile section
  • no "User not found" message

Why is this a problem?

The page assumes every GitHub API request is successful.

But fetch() does not automatically throw errors for failed responses like:

  • 403 (rate limit exceeded)
  • 404 (user not found)

Because of missing response checks:

  • the page crashes
  • invalid users render broken UI
  • users do not get proper feedback

How to fix it?

Before using API data, check if the response is successful using response.ok.

Example:

if (!userRes.ok) {
  throw new Error("User not found");
}

if (!prsRes.ok) {
  throw new Error("Failed to load pull requests");
}

setPRs(prsData.items ?? []);

This will:

  • prevent crashes
  • safely handle failed API responses
  • show proper error messages to users

Steps to Reproduce

Bug 1

  1. Open contributor profile pages multiple times quickly
  2. Trigger GitHub API rate limit
  3. Notice the page crashes

Bug 2

  1. Visit:
/contributor/thisisnotreal99999
  1. Observe broken empty profile page instead of proper error message

File Affected

src/pages/ContributorProfile/ContributorProfile.tsx

Metadata

Metadata

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions