Skip to content

fix: log fetch errors instead of silently swallowing them#6

Merged
alichherawalla merged 4 commits into
mainfrom
fix/home-fetch-errors
Feb 18, 2026
Merged

fix: log fetch errors instead of silently swallowing them#6
alichherawalla merged 4 commits into
mainfrom
fix/home-fetch-errors

Conversation

@alichherawalla
Copy link
Copy Markdown
Contributor

Summary

Tests

  • logs console.error when movies fetch fails — asserts the error message and error object are passed to console.error
  • logs console.error when genres fetch fails — same for the genres endpoint

Follows up on Gemini code review feedback from PR #5.

Test plan

  • pnpm --filter @stagepass/web test:coverage — 23/23 passing
  • CI green

🤖 Generated with Claude Code

Both fetch calls used empty .catch() — failures were invisible in dev
and production logs. Now logs with console.error. Also removes void
keyword from fetch calls per Gemini code review feedback (PR #5).
Two new tests verify that failed fetch calls log errors via
console.error rather than silently swallowing them.
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @alichherawalla, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the application's error handling by ensuring that network request failures are no longer silently ignored. By logging these errors, it improves debugging capabilities and provides better visibility into potential issues during data fetching, leading to a more stable and maintainable application. Additionally, it refines the code style by removing unnecessary keywords.

Highlights

  • Error Logging: Implemented robust error logging for failed API fetch calls in the Home component, replacing silent error swallowing with console.error to ensure failures are visible in development tools and production logs.
  • Code Style Improvement: Removed the non-idiomatic void keyword from fetch calls, as flagged by a previous code review.
  • Comprehensive Testing: Added new unit tests to specifically verify that console.error is invoked with the correct error messages when both movie and genre fetch operations fail.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • packages/web/src/pages/Home.test.tsx
    • Imported afterEach from vitest for test cleanup.
    • Declared and initialized consoleErrorSpy in beforeEach to mock console.error.
    • Restored the original console.error implementation in afterEach.
    • Added a test case to verify console.error is called when the movies fetch fails.
    • Added a test case to verify console.error is called when the genres fetch fails.
    • Updated test suite to include error logging tests for movie and genre fetches.
  • packages/web/src/pages/Home.tsx
    • Modified the .catch block for the movie fetch to log errors using console.error.
    • Removed the void keyword from the movie fetch call.
    • Modified the .catch block for the genre fetch to log errors using console.error.
    • Removed the void keyword from the genre fetch call.
    • Implemented error logging for failed movie and genre data fetches and removed the void keyword from fetch calls.
Activity
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Documents the fetch error logging step (remove void, log catch errors)
that was flagged in the Gemini code review on PR #5.
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request is a good improvement, as it ensures that fetch errors are logged instead of being silently ignored. The addition of tests to cover these failure scenarios is also great.

I've added one suggestion to improve the useEffect hook by adding a cleanup function with an AbortController. This is a best practice in React for handling asynchronous operations in effects to prevent potential memory leaks and race conditions if the component unmounts before the requests are complete.

Comment on lines 22 to 40
useEffect(() => {
void fetch('/api/movies')
fetch('/api/movies')
.then(res => res.json())
.then((data: Movie[]) => {
setMovies(data);
setLoading(false);
})
.catch(() => {
.catch((err: unknown) => {
console.error('Failed to fetch movies:', err);
setLoading(false);
});

void fetch('/api/movies/meta/genres')
fetch('/api/movies/meta/genres')
.then(res => res.json())
.then((data: string[]) => setGenres(data))
.catch(() => {});
.catch((err: unknown) => {
console.error('Failed to fetch genres:', err);
});
}, []);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The useEffect hook initiates asynchronous operations (fetches) but does not provide a cleanup function. This can lead to attempts to update state on an unmounted component if the component unmounts before the fetches complete, which will cause a memory leak and a warning from React.

It's a best practice to clean up effects that involve subscriptions or async requests. You can use an AbortController to cancel the fetch requests when the component unmounts. This will also require checking for AbortError in your catch blocks to avoid logging canceled requests as errors.

  useEffect(() => {
    const controller = new AbortController();
    const { signal } = controller;

    fetch('/api/movies', { signal })
      .then(res => res.json())
      .then((data: Movie[]) => {
        setMovies(data);
        setLoading(false);
      })
      .catch((err: any) => {
        if (err.name !== 'AbortError') {
          console.error('Failed to fetch movies:', err);
          setLoading(false);
        }
      });

    fetch('/api/movies/meta/genres', { signal })
      .then(res => res.json())
      .then((data: string[]) => setGenres(data))
      .catch((err: any) => {
        if (err.name !== 'AbortError') {
          console.error('Failed to fetch genres:', err);
        }
      });

    return () => {
      controller.abort();
    };
  }, []);

References docs/DESIGN_SYSTEM_GUIDE.md instead of the Memoria gist.
Updates page-by-page breakdown and checklist to match the light green
system (warm neutrals, green-to-teal gradient, Instrument Serif, DM Sans).
@alichherawalla alichherawalla merged commit 8adac66 into main Feb 18, 2026
1 check passed
@alichherawalla alichherawalla deleted the fix/home-fetch-errors branch February 18, 2026 07:08
alichherawalla added a commit that referenced this pull request Feb 18, 2026
…ount

useEffect had no cleanup — if the component unmounted before fetches
completed, React would attempt state updates on an unmounted component.
AbortController cancels both fetches on cleanup. AbortError is silently
ignored (not treated as a fetch failure) per Gemini review on PR #6.
alichherawalla added a commit that referenced this pull request Feb 18, 2026
…ount (#7)

* fix(Home): add AbortController cleanup to prevent memory leaks on unmount

useEffect had no cleanup — if the component unmounted before fetches
completed, React would attempt state updates on an unmounted component.
AbortController cancels both fetches on cleanup. AbortError is silently
ignored (not treated as a fetch failure) per Gemini review on PR #6.

* test(Home): assert AbortError is silently ignored, not logged as error

When a fetch is aborted (e.g. component unmount), the AbortError should
be swallowed — it is not a real failure. Verifies console.error is NOT
called when all fetches reject with an AbortError.

* chore: add coverage to .gitignore, delete stale docs copy files

coverage/ directories were untracked. Also removes accidental *copy.md
files that were left over from a previous session.

* fix(Home): check res.ok before parsing JSON on both fetch calls

fetch() only rejects on network errors — HTTP 4xx/5xx responses resolve
with a non-OK status. Without this check a 500 would try to parse an
error body as JSON and throw a cryptic error. Addresses high-priority
Gemini feedback on PR #7.

* test(Home): cover res.ok HTTP error check and update mock responses

Adds two tests that verify a non-OK HTTP response (4xx/5xx) is treated
as an error and logged via console.error. Updates all existing mocks to
include ok: true to match the new res.ok guard.
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.

1 participant