Skip to content

Guard GithubRepos against non-array/error GitHub API responses before slicing#25

Merged
Yasar2019 merged 3 commits into
mainfrom
copilot/guard-github-repos-against-errors
Apr 4, 2026
Merged

Guard GithubRepos against non-array/error GitHub API responses before slicing#25
Yasar2019 merged 3 commits into
mainfrom
copilot/guard-github-repos-against-errors

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 4, 2026

GithubRepos.jsx assumed the GitHub repos API always returned an array and called .slice() unconditionally. On rate-limit/error responses (object payloads), this could throw at runtime.

  • Response handling hardening

    • Added an explicit response.ok gate before JSON parsing.
    • Throws a request-level error when the HTTP response is not successful.
  • Data-shape validation

    • Added Array.isArray(data) validation before calling .slice(0, 5).
    • Throws a distinct format-level error if the payload is not an array.
  • Behavioral impact

    • Prevents runtime crashes from .slice on non-array payloads.
    • Keeps existing success-path behavior unchanged (still shows latest 5 repos).
fetch("https://api.github.com/users/Yasar2019/repos")
  .then((response) => {
    if (!response.ok) {
      throw new Error("GitHub API request failed");
    }
    return response.json();
  })
  .then((data) => {
    if (!Array.isArray(data)) {
      throw new Error("GitHub API returned invalid data format");
    }
    setRepos(data.slice(0, 5));
  });

Copilot AI changed the title [WIP] Guard GithubRepos.jsx against non-array API responses Guard GithubRepos against non-array/error GitHub API responses before slicing Apr 4, 2026
Copilot AI requested a review from Yasar2019 April 4, 2026 17:48
Copy link
Copy Markdown
Owner

@Yasar2019 Yasar2019 left a comment

Choose a reason for hiding this comment

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

good

@Yasar2019 Yasar2019 marked this pull request as ready for review April 4, 2026 20:03
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 4, 2026

Azure Static Web Apps: Your stage site is ready! Visit it here: https://witty-mud-031b23a0f-25.eastus2.2.azurestaticapps.net

@Yasar2019 Yasar2019 merged commit 91ffa2b into main Apr 4, 2026
2 checks passed
@Yasar2019 Yasar2019 deleted the copilot/guard-github-repos-against-errors branch April 4, 2026 20:07
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.

Guard GithubRepos.jsx against non-array API responses before calling .slice()

2 participants