fix: Raise a Seam error for a success response that is malformed - #1005
Merged
Conversation
A 200 response with an unexpected envelope, such as a proxy rewrite or a gateway page with a JSON content type, escaped the SDK error hierarchy entirely: reading a missing response key produced undefined, which surfaced as a bare TypeError from the action attempt poller or as undefined response data. The paginator threw plain Error objects for the same class of failure. Centralize the response unwrap in readResponseData and raise the new SeamHttpInvalidResponseError, which names the endpoint path and the expected response key. The paginator uses the same guard for the list data and the pagination object. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B8xeJm2Hd923k8uo6eoFd2
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.
Problem
SDK audit finding M3 (medium): a 200 with an unexpected envelope (proxy rewrite, gateway maintenance page with a JSON content type, response-key rename) bypassed all typed errors.
execute()readresponse[responseKey]unguarded, returningundefinedor feeding it into the action-attempt poller, which crashed with a bareTypeError: Cannot read properties of undefined (reading 'status'). The paginator threw plainErrorobjects for the same class of failure, and a missingpaginationobject silently truncated iteration to one page.Fix
Mirrors seamapi/php#475. Centralize the response unwrap in an exported
readResponseDatahelper and raise a newSeamHttpInvalidResponseError(withpathandresponseKeyproperties, plus anisSeamHttpInvalidResponseErrorguard) whose message names the endpoint and the missing key:The paginator uses the same guard for the list value (
got string instead of a list), for a missingpaginationobject, and for a non-objectpaginationvalue — no more silent one-page truncation.Tests
7 new nock-driven tests pin the exact messages: missing key, non-object body,
nullbody, malformed action-attempt response, non-list data, missing pagination, non-object pagination. Per the audit-notes recipe, with the guards reverted all 7 fail with the audit's exact symptoms (bare TypeErrors, including the poller'sreading 'status'). Full suite (132 tests), lint, typecheck green.Part of applying the rev-3 SDK audit (one PR per finding). Related: #1002, #1003, #1004.
🤖 Generated with Claude Code
https://claude.ai/code/session_01B8xeJm2Hd923k8uo6eoFd2
Generated by Claude Code