Skip to content

fix: handle network errors in pi API client - #3058

Open
abhijeet117 wants to merge 2 commits into
upstash:masterfrom
abhijeet117:fix/pi-api-network-error-handling
Open

fix: handle network errors in pi API client#3058
abhijeet117 wants to merge 2 commits into
upstash:masterfrom
abhijeet117:fix/pi-api-network-error-handling

Conversation

@abhijeet117

Copy link
Copy Markdown

Summary

The pi package API functions called fetch without try-catch, so network failures (DNS errors, timeouts, connection resets) surfaced as unhandled exceptions and crashed the tool call instead of returning a readable error. Wrapped searchLibraries and fetchLibraryContext in try-catch, matching the MCP package implementation, so failures return user-friendly error strings.

Testing

Reproduced by mocking fetch to reject with a network error; both functions threw before the fix and now return error messages instead. Added packages/pi/tests/api.test.ts covering network failures, non-ok statuses, empty bodies, and successful responses. All 11 pi package tests pass.

Checklist

  • bug reproduced before fix
  • root cause identified
  • bug fixed
  • tests passed

The pi package API functions called fetch without try-catch, causing unhandled rejections on network failures. Wrapped both functions in try-catch to return user-friendly error messages.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant