Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: redundant validation #66

Open
wit03 opened this issue Oct 9, 2024 · 0 comments
Open

fix: redundant validation #66

wit03 opened this issue Oct 9, 2024 · 0 comments

Comments

@wit03
Copy link
Member

wit03 commented Oct 9, 2024

          _:warning: Potential issue_

LGTM! Consider refining the response structure validation.

The new getRealTimeRetroPGF6 function is well-structured and consistent with getRealTimeRetroPGF5. However, there's a potential issue in the response structure validation.

The condition !Array.isArray(data.data) is checked twice. The second check seems redundant and might be a copy-paste error. Consider updating the validation as follows:

 if (
   !Array.isArray(data.data) ||
-  data.data.length === 0 ||
-  !Array.isArray(data.data)
+  data.data.length === 0
 ) {
   throw new Error('Unexpected response structure')
 }

This change ensures that data.data is an array and is not empty, which appears to be the intended validation.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

export const getRealTimeRetroPGF6 = async (): Promise<iRetroPGF6Project[]> => {
  try {
    const baseUrl =
      process.env.NODE_ENV === 'production'
        ? process.env.NEXT_PUBLIC_WORKER_API_BASE
        : process.env.NEXT_PUBLIC_WORKER_API_DEV

    if (!baseUrl) {
      throw new Error('API base URL is not defined in environment variables.')
    }
    const apiUrl = baseUrl + '/api/retropgf6-live-data/retropgf6-live-data.json'
    const response = await axios.get<WorkerResponseRound6>(apiUrl)
    const data: WorkerResponseRound6 = response.data
    if (
      !Array.isArray(data.data) ||
      data.data.length === 0
    ) {
      throw new Error('Unexpected response structure')
    }
    return data.data
  } catch (error) {
    console.error('Error fetching data:', error)
    throw error
  }
}

Originally posted by @coderabbitai[bot] in #46 (comment)

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

No branches or pull requests

1 participant