Skip to content

Add Consistent Error Handling Across API Service Methods #42

Description

@AkshitRaiKakkar

Requested Changes

I noticed that the API service methods currently do not include any error handling. This can lead to unhandled promise rejections when the backend returns an error (4xx/5xx) or when there is a network failure.

Requested Changes:

  • Wrap all API calls in try...catch blocks.
  • Log the error appropriately for debugging.
  • Re-throw the error so that the calling component can handle it (e.g., display an error message or retry).
  • Apply this consistently across all service methods (getAllTasks, getTaskById, scheduleTask, updateTask, and any similar API services).

Reason:

  • Prevents unhandled promise rejections.
  • Improves application stability during API failures.
  • Makes debugging easier through consistent error logging.
  • Allows UI components to implement proper error handling and user feedback.

Example:

export const getTaskById = async (id) => {
  try {
    const response = await API.get(`/api/maintenance/${id}`);
    return response.data;
  } catch (error) {
    console.error("Failed to fetch maintenance task:", error);
    throw error;
  }
};

I can work on implementing these changes across the API service layer to ensure consistent error handling throughout the project.

Metadata

Metadata

Labels

ECSoC26-L2Medium (Intermediate)ECSoc26Required for ECSOC SentinelbugSomething isn't workingenhancementNew feature or requestgood first issueGood for newcomersgood-issueGood issue

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions