classroom icon indicating copy to clipboard operation
classroom copied to clipboard

fix: prevent page crashes when mock-fcc-data server is offline

Open AbiramiR-27 opened this issue 5 months ago • 4 comments

Checklist:

Closes #533

Description of Changes

This PR resolves page crashes (like on /dashboard and /dashboard/v2/details) when the mock-fcc-data JSON server is not running or the MOCK_USER_DATA_URL environment variable is missing.

Key changes include:

  • Graceful API Fetch Failure: Wrapped the main mock student dataset fetch in try/catch blocks inside util/student/fetchStudentData.js, defaulting to an empty array ([]) and warning/logging the error instead of throwing uncaught runtime exceptions.
  • Defensive Parameter Checks: Added type checking (Array.isArray()) and truthiness safety guards to traversal utility methods (getStudentProgressInSuperblock, extractStudentCompletionTimestamps, extractFilteredCompletionTimestamps, and checkIfStudentHasProgressDataForSuperblocksSelectedByTeacher) to handle empty fallback student data cleanly.
  • Resilient Dashboard Rendering: Added checks to the student loop inside pages/dashboard/v2/[id].js to prevent crashing when studentData or certification options are empty.

AbiramiR-27 avatar Jun 10 '26 15:06 AbiramiR-27

Thank you for the review and the detailed feedback!

I'll remove the unrelated changes from navbar.js, [...nextauth].js, and navbar.test.jsx and update the PR accordingly. I'll also address the comments regarding the null-proof checks and the forEach index optimization. Regarding the fetch error handling suggestion, I agree that returning distinct error codes would provide better visibility into the failure state. Since the current implementation resolves the crash issue, I can either incorporate that enhancement in this PR if preferred or handle it as a follow-up issue.

Thanks again for the suggestions!

AbiramiR-27 avatar Jun 14 '26 03:06 AbiramiR-27

Hey @utsab ! Can u please review this pr, NewtonLC reviewed and is satisfied with my changes

AbiramiR-27 avatar Jul 06 '26 08:07 AbiramiR-27

Hi @AbiramiR-27!

Right now, we're working with the FreeCodeCamp maintainers to get the stack deployed, which will involve student and teacher onboarding workflows (PRs #595 and #600). Once that's in place, we'll be able to review both of your PRs. Thanks again for working on them, and for sticking with the Classroom app project!

NewtonLC avatar Jul 06 '26 21:07 NewtonLC

Thanks for the update! I understand. Thanks again!

AbiramiR-27 avatar Jul 07 '26 05:07 AbiramiR-27

Hi @utsab @NewtonLC , just following up to see if you have any updates on this PR.

AbiramiR-27 avatar Aug 13 '26 05:08 AbiramiR-27