fix(api): show meaningful message for network errors instead of '0 Unknown'#572
fix(api): show meaningful message for network errors instead of '0 Unknown'#572
Conversation
…known' When an API request fails at the network level (DNS failure, timeout, ECONNREFUSED, etc.), the response object is undefined. Previously, throwApiError() produced 'Failed to ...: 0 Unknown' which gives users no useful information. Now it produces 'Failed to ...: Network error' with a detail message that includes the underlying cause (e.g., 'fetch failed', 'connect ECONNREFUSED 127.0.0.1:443') and a suggestion to check internet connectivity. Fixes CLI-G3 (7 users, 35 events across 0.19.0/0.20.0)
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨Dashboard
Init
Other
Bug Fixes 🐛Dashboard
Other
Internal Changes 🔧Coverage
Other
🤖 This preview updates automatically when you update the PR. |
Codecov Results 📊✅ 126 passed | Total: 126 | Pass Rate: 100% | Execution Time: 0ms 📊 Comparison with Base Branch
✨ No test changes detected All tests are passing successfully. ✅ Patch coverage is 100.00%. Project has 1274 uncovered lines. Files with missing lines (1)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 95.43% 95.43% —%
==========================================
Files 194 194 —
Lines 27894 27903 +9
Branches 0 0 —
==========================================
+ Hits 26620 26629 +9
- Misses 1274 1274 —
- Partials 0 0 —Generated by Codecov Action |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
…rmat() ApiError.format() only indents the first line of detail with '\n '. Continuation lines need explicit indentation to maintain the aligned error layout.
|
Addressed Cursor Bugbot feedback: fixed the multi-line detail indentation for |

Summary
When an API request fails at the network level (DNS failure, timeout, ECONNREFUSED, etc.), the response object is undefined. Previously,
throwApiError()produced cryptic messages like:This gives users no useful information about what went wrong.
Fix
Now it produces a meaningful message:
The detail includes the underlying cause (e.g.,
fetch failed,connect ECONNREFUSED 127.0.0.1:443) and a suggestion to check internet connectivity.Sentry Issue
Fixes CLI-G3 (7 users, 35 events across 0.19.0/0.20.0)
Changes
src/lib/api/infrastructure.ts: Added network-failure detection inthrowApiError()whenresponseis undefinedtest/lib/api/infrastructure.test.ts: New test file covering network errors, HTTP errors, and edge cases