Skip to content

fix: improve error handling in data fetching functions#58

Merged
fityannugroho merged 1 commit intomainfrom
fix-data-fetching
May 16, 2025
Merged

fix: improve error handling in data fetching functions#58
fityannugroho merged 1 commit intomainfrom
fix-data-fetching

Conversation

@fityannugroho
Copy link
Owner

PR Checklist

Please check if your PR fulfills the following requirements:

  • I have read the documentation.
  • I have read and followed the Contributing Guidelines.
  • I have included a pull request description of my changes.
  • I have included the necessary changes to the documentation.
  • I have added tests to cover my changes.

PR Type

What kind of change does this PR introduce?

  • Bug fix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes

What is the current behavior?

getData and getBoundaryData server actions will throw 500 error when the servers that defined in .env (DATA_SOURCE_URL and DATA_SOURCE_BOUNDARY_URL) is unreachable/inactive.

What is the new behavior?

This pull request improves error handling and network robustness in the data and useBoundary modules. The changes include adding more descriptive error messages, handling network connection failures, and ensuring consistent error responses.

Enhancements to error handling:

  • hooks/useBoundary.ts: Updated the error message logic to include res.message if available, providing more specific error details when an unexpected status code is encountered.

  • lib/data.ts:

    • getData: Added a try-catch block to handle network connection errors gracefully. If a connection fails, it now returns a structured error response with a 500 status code and a descriptive message. Additionally, improved error messaging for non-OK responses by including the response body text.
    • getBoundaryData: Similar to getData, added a try-catch block to handle network errors and return a structured error response with a 500 status code and a descriptive message. Changed the URL construction to use the URL class for better readability and maintainability.

@fityannugroho fityannugroho added the bug Something isn't working label May 16, 2025
@vercel
Copy link

vercel bot commented May 16, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
idn-area-map ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 16, 2025 2:13pm

@fityannugroho fityannugroho merged commit 1b68ee0 into main May 16, 2025
8 checks passed
@fityannugroho fityannugroho deleted the fix-data-fetching branch May 16, 2025 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant