AthletiFi / athletifi-website

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

Resolve API Data Retrieval error #343

Closed qisforq closed 2 days ago

qisforq commented 3 days ago

Task Description: Resolve Dashboard API Data Retrieval Error

Objective: Fix the recurring TypeError in the GET handler of the /api/dashboard/[...cardId] route to ensure robust data retrieval and error handling for the AthletiFi dashboard.

Steps:

  1. Code Review and Debugging:

    • Locate and examine the file: src/app/api/dashboard/[...cardId]/route.ts
    • Focus on line 17, where the error is occurring
    • Identify the cause of the "Cannot read properties of null (reading '0')" error
  2. Implement Null Checks:

    • Add proper null and undefined checks before accessing any data properties
    • Ensure that the cardId parameter is correctly extracted and validated
  3. Error Handling Enhancement:

    • Implement a try-catch block around the main logic of the GET handler
    • Create meaningful error responses for different scenarios (e.g., data not found, database error)
  4. Data Retrieval Verification:

    • Review the database query or data fetching logic
    • Ensure that the correct data is being retrieved based on the provided cardId
    • Verify the structure of the returned data matches what the code expects
  5. Testing:

    • Create unit tests for the GET handler to cover various scenarios (successful data retrieval, no data found, invalid cardId)
    • Perform integration tests to ensure proper communication between the API, Lambda, and RDS PostgreSQL database
  6. Documentation:

    • Update any relevant documentation about the API endpoint
    • Document the error handling approach and expected response formats
  7. Logging Implementation:

    • Add detailed logging throughout the function to aid in future debugging
    • Ensure logs capture relevant information like cardId, query parameters, and error details
  8. Code Optimization:

    • Refactor the code if necessary to improve readability and maintainability
    • Consider extracting reusable parts into separate functions
  9. Pull Request and Code Review:

    • Create a pull request with the changes
    • Provide a detailed description of the changes and the problem they solve
    • Request a code review from team members
  10. Deployment and Monitoring:

    • Once approved, deploy the changes to a staging environment
    • Monitor the logs and performance to ensure the error has been resolved
    • Plan for deployment to production after successful staging tests

Definition of Done:

Estimated time: 4-6 hours

Priority: High

Assigned to: [Developer Name]

By completing this task, we will improve the stability and reliability of the AthletiFi dashboard, ensuring a better experience for our users when accessing player data and analytics.

pm-moyanor commented 2 days ago

Wasn't able to reproduce the error. It seems likely fixed along with @chef-louis #347 and #345 logging cleanup. merged changes, test again with @qisforq to see if the issue persists

qisforq commented 2 days ago

Yeah you are probably right, reading over them again they were pretty similar bugs. Thanks for taking care of the merges!