Skip to content

Missing Error Handling for API Calls #179

@codeCraft-Ritik

Description

@codeCraft-Ritik

Summary:

The code fetches data from the GitHub API but does not handle scenarios where the request fails (e.g., 404 Not Found, 403 Rate Limited, or 500 Server Error). This causes the application to attempt to read properties like result.full_name from an error response or undefined object, leading to runtime crashes.

Fix:

Implement try-catch blocks and check the response.ok status before processing data.

Corrected Code Snippet (Logic for loadActiveRepoDetails.js):

try {
    const response = await fetch(repo_endpoint, { /* headers */ });
    
    if (!response.ok) {
        console.error(`Error fetching ${repo_name}: ${response.statusText}`);
        return null;
    }
    
    const result = await response.json();
    // ... processing
} catch (error) {
    console.error("Network or parsing error:", error);
    return null;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions