Skip to content

fix(client): use JSON error identifiers as fallback codes - #407

Open
kartojal wants to merge 1 commit into
mainfrom
fix/relayer-error-code-fallback
Open

kartojal wants to merge 1 commit into
mainfrom
fix/relayer-error-code-fallback

Conversation

@kartojal

@kartojal kartojal commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Fixes DEFIQA-2402 for the Python SDK. TypeScript counterpart: Polymarket/ts-sdk#501.

RequestRejectedError.code was only filled from a code field in the response body. The relayer now answers 403 with {"error":"NOT_ALLOWED"}, and other services send lower-case identifiers such as {"error":"signer_does_not_match_account"}, so code came back as None.

When there is no code field, the transport now uses error as the code if it is a lower- or upper-case snake_case identifier and the status is not 400. Free-text messages and 400 validation details are unchanged. This matches the TypeScript SDK's behavior.

Testing

  • Parametrized test_transport.py case covering 403 NOT_ALLOWED, 422 lower-case identifier, 403 free text, and 400 identifier
  • uv run pytest tests/unit: all pass except two deposit-wallet tests that make live network calls and fail on main too
  • uv run ruff check, uv run ruff format --check, uv run pyright

🤖 Generated with Claude Code


Note

Low Risk
Narrow change to HTTP error parsing in the transport layer, with unit tests and no auth or data-path impact.

Overview
RequestRejectedError.code was only populated from a JSON code field, so responses like relayer 403 with {"error":"NOT_ALLOWED"} or other services with snake_case error values left code as None.

The transport’s _extract_response_error_code now treats error as the code when there is no code, the status is not 400, and error matches a snake_case identifier (upper or lower). Human-readable error strings and 400 validation bodies still do not set code, aligning with the TypeScript SDK.

Tests assert 400 keeps code None and add a parametrized case for NOT_ALLOWED, lower-case identifiers, free text, and 400 bodies.

Reviewed by Cursor Bugbot for commit eee289d. Bugbot is set up for automated code reviews on this repo. Configure here.

Rejected requests only read `code` from the response body. Services
that send just a stable identifier in `error`, such as the relayer's
403 `{"error":"NOT_ALLOWED"}`, left `RequestRejectedError.code` empty.
Promote lower- or upper-case snake_case `error` values to `code` for
non-400 responses, matching the TypeScript SDK.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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