Skip to content

Map Bitget API error codes to internal solver errors#4285

Merged
squadgazzz merged 3 commits intomainfrom
bitget-error-code-mapping
Mar 23, 2026
Merged

Map Bitget API error codes to internal solver errors#4285
squadgazzz merged 3 commits intomainfrom
bitget-error-code-mapping

Conversation

@squadgazzz
Copy link
Contributor

@squadgazzz squadgazzz commented Mar 23, 2026

Description

  • Parse error_code and message fields from Bitget API responses (previously only status and data were parsed)
  • Map Bitget error codes (80000–80010) to appropriate internal error variants:
    • NotFound: 80001 (insufficient balance), 80002 (below min), 80003 (above max), 80004 (expired), 80005 (no liquidity), 80008 (reverse quote), 80009 (token info), 80010 (price info)
    • BadRequest: 80006 (illegal request)
    • Api (logged): 80000 (internal), 80007 (partner invalid), unknown codes
  • Handle HTTP 429 explicitly as RateLimited before the generic status check

Previously all non-zero status values except hardcoded 404/429 fell through to a generic Api error, which led to a lot of alert noise. The old 404/429 mapping in handle_api_error didn't match the actual Bitget API format (which uses status: 0/1 + error_code: 80xxx).

Error code reference: https://web3.bitget.com/en/docs/swap-order#error-code-list

How to test

  • All 5 existing bitget tests pass (cargo nextest run -p solvers bitget)
  • Updated not_found test to use the actual Bitget error response format (status: 1, error_code: 80005)

Parse `error_code` and `message` from Bitget API responses and map
them to the appropriate internal error variants instead of treating
all non-zero statuses as generic API errors.

Error code reference: https://web3.bitget.com/en/docs/swap-order#error-code-list
@squadgazzz squadgazzz requested a review from a team as a code owner March 23, 2026 17:20
@squadgazzz squadgazzz marked this pull request as draft March 23, 2026 17:20
@squadgazzz squadgazzz added the hotfix Labels PRs that should be applied into production right away label Mar 23, 2026
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors Bitget API error handling to utilize specific error_code and message fields from the API response. This includes updating the Response DTO, modifying the handle_api_error function to process these new fields, introducing a BadRequest error type, and updating the Error enum and its conversions. Test cases have also been adjusted to reflect the new error response structure. I have no feedback to provide.

@squadgazzz squadgazzz marked this pull request as ready for review March 23, 2026 18:01
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the Bitget API error handling to utilize more granular error codes and messages. The Response DTO now includes error_code and message fields, and the handle_api_error function has been updated to parse these new fields, mapping specific Bitget error codes to internal NotFound and BadRequest error types. The Error enum and its conversion from bitget::Error have been adjusted, and the request function now explicitly handles rate limiting and passes the new error details. A test case was also updated to reflect the new error response format. The review suggests an improvement to the handle_api_error function's message parameter, recommending it be changed from String to Option<String> to enhance efficiency by avoiding unnecessary allocations, along with corresponding updates to its call sites.

@squadgazzz squadgazzz force-pushed the bitget-error-code-mapping branch from 29b90e2 to 00ba4cd Compare March 23, 2026 18:41
@squadgazzz
Copy link
Contributor Author

The failing audit is fixed in #4286

@squadgazzz squadgazzz removed the hotfix Labels PRs that should be applied into production right away label Mar 23, 2026
@squadgazzz squadgazzz enabled auto-merge March 23, 2026 20:48
@squadgazzz squadgazzz added this pull request to the merge queue Mar 23, 2026
Merged via the queue into main with commit eb71b52 Mar 23, 2026
19 checks passed
@squadgazzz squadgazzz deleted the bitget-error-code-mapping branch March 23, 2026 21:03
@github-actions github-actions bot locked and limited conversation to collaborators Mar 23, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants