Skip to content

feat: improve centralized API integration and error handling#211

Open
askr09 wants to merge 2 commits into
rdodiya:gssoc_developfrom
askr09:fix/api-error-handling-clean
Open

feat: improve centralized API integration and error handling#211
askr09 wants to merge 2 commits into
rdodiya:gssoc_developfrom
askr09:fix/api-error-handling-clean

Conversation

@askr09
Copy link
Copy Markdown

@askr09 askr09 commented May 24, 2026

Summary

Improved the centralized API integration layer by enhancing API error handling and response parsing.

Changes Made

  • Added improved centralized API error handling
  • Added safer JSON response parsing
  • Improved debugging support for API failures
  • Enhanced maintainability and scalability of API communication

Technical Improvements

  • Added structured error message handling
  • Prevented crashes caused by invalid JSON responses
  • Improved API request reliability
  • Added fallback error handling for malformed responses

Issue

Closes #90

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances the frontend’s centralized public API helper by improving fetch error handling and making response parsing more resilient, aligning with Issue #90’s goal of a scalable API communication layer.

Changes:

  • Improve non-2xx error handling by attempting to extract a structured error message from the response body.
  • Add guarded JSON parsing to reduce crashes on malformed responses.
  • Add debugging logs to aid diagnosing API failures.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 20 to +24
const response = await fetch(url, { ...defaultOptions, ...options });

if (!response.ok) {
throw new Error(`API Error: ${response.status} ${response.statusText}`);
if (!response.ok) {
let errorMessage = `API Error: ${response.status}`;

try {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed the review feedback by improving response handling for:

  • Empty responses (204/205)
  • Non-JSON responses
  • Safer content-type based parsing
  • Better fallback error messages

Updated in the latest commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create API Integration Layer for Frontend-Backend Communication

3 participants