Always implement explicit error handling for external operations such as network requests, database queries, and API calls. When errors occur, either:
Always implement explicit error handling for external operations such as network requests, database queries, and API calls. When errors occur, either:
Avoid simply logging errors without proper handling or recovery strategy.
Example - Before:
async function fetchDatabaseExtensions() {
try {
const dbExtensions = await getDatabaseExtensions(
{ projectRef, connectionString },
undefined,
headers
)
effectiveAiOptInLevel = checkNetworkExtensionsAndAdjustOptInLevel(
dbExtensions,
effectiveAiOptInLevel
)
} catch (error) {
console.error('Failed to fetch database extensions:', error)
// No error handling strategy - neither degrading nor propagating
}
}
Example - After:
async function fetchDatabaseExtensions() {
try {
const dbExtensions = await getDatabaseExtensions(
{ projectRef, connectionString },
undefined,
headers
)
effectiveAiOptInLevel = checkNetworkExtensionsAndAdjustOptInLevel(
dbExtensions,
effectiveAiOptInLevel
)
} catch (error) {
console.error('Failed to fetch database extensions:', error)
// Option 1: Degrade functionality gracefully
effectiveAiOptInLevel = 'restricted' // Default to restricted access on error
// Option 2: Propagate the error to fail explicitly
// throw new Error(`Database extensions check failed: ${error.message}`)
}
}
Enter the URL of a public GitHub repository