Map Bitget API error codes to internal solver errors#4285
Conversation
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
29b90e2 to
00ba4cd
Compare
|
The failing audit is fixed in #4286 |
Description
error_codeandmessagefields from Bitget API responses (previously onlystatusanddatawere parsed)RateLimitedbefore the generic status checkPreviously all non-zero
statusvalues except hardcoded 404/429 fell through to a genericApierror, which led to a lot of alert noise. The old 404/429 mapping inhandle_api_errordidn't match the actual Bitget API format (which usesstatus: 0/1+error_code: 80xxx).Error code reference: https://web3.bitget.com/en/docs/swap-order#error-code-list
How to test
cargo nextest run -p solvers bitget)not_foundtest to use the actual Bitget error response format (status: 1, error_code: 80005)