AthletiFi / athletifi-website

Official website for AthletiFi
https://www.athleti.fi
1 stars 5 forks source link

BUG: Card Data undefined #345

Closed qisforq closed 2 days ago

qisforq commented 3 days ago

Task: Debug and Fix Dashboard API Data Retrieval Error Objective: Resolve the TypeError occurring in the GET handler of the /api/dashboard/[...cardId] route, specifically for card ID 4, to ensure proper data retrieval and error handling for the AthletiFi dashboard.

Steps:

  1. Code Investigation:

    • Examine src/app/api/dashboard/[...cardId]/route.ts, focusing on line 17
    • Identify why the code is attempting to access index [0] of a null value
  2. Data Flow Analysis:

    • Trace the data flow for card ID 4
    • Verify if the database query is returning expected results for this specific card
  3. Implement Null Checks:

    • Add null checks before accessing any properties of the retrieved data
    • Handle cases where the data might be null or undefined
  4. Error Handling:

    • Implement a try-catch block in the GET handler
    • Create an appropriate error response for when data is not found or is null
  5. Logging:

    • Add detailed logging to capture the state of the data at each step
    • Log the cardId being processed and any query parameters
  6. Testing:

    • Create a test case specifically for card ID 4
    • Ensure the handler works correctly for both card ID 4 and 5 (which seems to be working)
  7. Database Query Review:

    • Review and potentially optimize the database query for fetching card data
    • Ensure consistent data structure is returned for all card IDs
  8. Code Refactoring:

    • Consider extracting the data fetching logic into a separate function for better maintainability
  9. Update API Documentation:

    • Document the possible response scenarios (success, not found, error)
    • Update any API documentation to reflect changes in error handling
  10. Pull Request and Code Review:

    • Create a pull request with the changes
    • Provide before and after examples in the PR description

Definition of Done:

Estimated time: 3-4 hours

Priority: High

Assigned to: [Developer Name]

By completing this task, we will improve the reliability of the AthletiFi dashboard API, ensuring consistent behavior across different card IDs and providing a better experience for users accessing player data.

qisforq commented 3 days ago

Add Error handling and optional chaining

chef-louis commented 3 days ago

I'm not able to reproduce the same error on my local setup. Will coordinate with @qisforq to resolve the issue and see if there are any deeper problems that need fixing.