Skip to content

feat: throw ConnectionRefusedError when ECONNREFUSED is detected#659

Open
Dwifax wants to merge 1 commit into
StellarCommons:mainfrom
Dwifax:feat/econnrefused-error-handling
Open

feat: throw ConnectionRefusedError when ECONNREFUSED is detected#659
Dwifax wants to merge 1 commit into
StellarCommons:mainfrom
Dwifax:feat/econnrefused-error-handling

Conversation

@Dwifax

@Dwifax Dwifax commented Jun 29, 2026

Copy link
Copy Markdown

Summary

When the Stellar Explain backend is down or unreachable, Node.js fetch throws a TypeError with cause.message containing "ECONNREFUSED". Previously this was caught by the generic NetworkError fallback, giving users a confusing "Request failed: fetch failed" message with no hint about the root cause.

This PR adds a specific ConnectionRefusedError that clearly tells users:

Connection refused at http://... Is the Stellar Explain backend running?

Changes

  • errors.ts: New ConnectionRefusedError class with EXIT_CODE.ERROR
  • client.ts: Detect ECONNREFUSED in cause.message before falling through to generic NetworkError
  • client.test.ts: 2 new tests:
    • ECONNREFUSEDConnectionRefusedError
    • ENOTFOUNDNetworkError fallthrough ✓

Test Results

✓ packages/cli/tests/client.test.ts (14 tests) 27ms
  Test Files  1 passed (1)
       Tests  14 passed (14)

Detect ECONNREFUSED in fetch error cause chain and throw a
specific ConnectionRefusedError instead of a generic NetworkError.
This gives users a clear 'Is the backend running?' hint when
the Stellar Explain server is not reachable.

- Add ConnectionRefusedError to errors.ts
- Detect cause.message.includes('ECONNREFUSED') in client.ts
- Add 2 tests: ECONNREFUSED → ConnectionRefusedError, ENOTFOUND → NetworkError fallthrough
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