Skip to content

feat(http-request): add hooks, maxResponseSize, rawResponse, enriched errors#133

Merged
jdalton merged 9 commits intomainfrom
feat/http-request-hooks
Apr 4, 2026
Merged

feat(http-request): add hooks, maxResponseSize, rawResponse, enriched errors#133
jdalton merged 9 commits intomainfrom
feat/http-request-hooks

Conversation

@jdalton
Copy link
Copy Markdown
Collaborator

@jdalton jdalton commented Apr 4, 2026

Summary

  • Hooks (onRequest/onResponse): Lifecycle hooks on HttpRequestOptions that fire per-attempt — retries and redirects each trigger separate hook calls. Enables observability (perfTimer, logging, telemetry) without coupling it into the transport.
  • maxResponseSize: Optional byte limit on response bodies. Rejects with a clear error (exceeds maximum size limit (X.XXmb > Y.YYmb)) and destroys the stream early. Works through redirects, httpJson, and httpText.
  • rawResponse: Exposes the underlying IncomingMessage on HttpResponse for advanced consumers that need stream-level access (e.g., SDK adapter pattern).
  • enrichErrorMessage: Exported function that enriches error messages based on error code (ECONNREFUSED, ENOTFOUND, ETIMEDOUT, ECONNRESET, EPIPE, CERT_HAS_EXPIRED, UNABLE_TO_VERIFY_LEAF_SIGNATURE). Generic guidance, no product-specific branding.
  • New exported types: HttpHooks, HttpHookRequestInfo, HttpHookResponseInfo

Prepares socket-lib to be the shared HTTP transport for socket-sdk-js (replacing its independent http-client.ts implementation).

Test plan

  • 23 new tests covering hooks, maxResponseSize, rawResponse, enrichErrorMessage
  • Deduped from 141 → 123 total tests while preserving all coverage
  • All 6382+ existing lib tests pass
  • Build passes (pnpm run build)

jdalton added 5 commits April 3, 2026 22:32
… errors

- onRequest/onResponse hooks fire per-attempt (retries/redirects each trigger)
- maxResponseSize rejects responses exceeding byte limit
- rawResponse exposes IncomingMessage on HttpResponse for advanced use
- Enriched error messages for ECONNREFUSED, ENOTFOUND, ETIMEDOUT,
  ECONNRESET, EPIPE, and SSL/TLS cert errors
- New exported types: HttpHooks, HttpHookRequestInfo, HttpHookResponseInfo
…nse, enrichErrorMessage

- hooks: onRequest/onResponse fire per-attempt, per-redirect, with POST method, custom headers
- maxResponseSize: rejects oversized responses, works with httpJson/httpText, fires error hooks
- rawResponse: exposes IncomingMessage on success and non-2xx responses
- enrichErrorMessage: tests all 7 error codes + unknown + no-code cases
- Export enrichErrorMessage for testability
…atures

- hooks edge cases: onRequest-only, onResponse-only, empty hooks, httpJson/httpText passthrough, response headers in hook, duration
- maxResponseSize edge cases: exact size match, zero (no limit), enforcement after redirect
- rawResponse edge cases: after redirect (final response), on server error
- enriched errors integration: method+url in timeout, method+url in connection error, cause chain preserved, url in enrichErrorMessage
…41 → 123)

Merge duplicate test sections into single describe blocks. Combine
tests that hit the same endpoint with identical setup. Use parameterized
test for enrichErrorMessage error codes. All coverage preserved.
@jdalton jdalton force-pushed the feat/http-request-hooks branch from 7b54b2c to 6943ccb Compare April 4, 2026 02:32
@jdalton jdalton merged commit 8d771cb into main Apr 4, 2026
12 checks passed
@jdalton jdalton deleted the feat/http-request-hooks branch April 4, 2026 02:52
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