feat(http-request): add hooks, maxResponseSize, rawResponse, enriched errors#133
Merged
feat(http-request): add hooks, maxResponseSize, rawResponse, enriched errors#133
Conversation
… 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.
7b54b2c to
6943ccb
Compare
…array-simple rule
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
onRequest/onResponse): Lifecycle hooks onHttpRequestOptionsthat 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 underlyingIncomingMessageonHttpResponsefor 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.HttpHooks,HttpHookRequestInfo,HttpHookResponseInfoPrepares socket-lib to be the shared HTTP transport for socket-sdk-js (replacing its independent
http-client.tsimplementation).Test plan
pnpm run build)