Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse Binance API error response #2912

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

peterzen
Copy link
Member

@peterzen peterzen commented Aug 12, 2024

This change parses API error details from error responses.

@peterzen peterzen force-pushed the binance-api-req branch 2 times, most recently from 4adf0f7 to ac3a51c Compare September 14, 2024 13:54
Comment on lines -1920 to +1939
return dexnet.Do(req, thing, dexnet.WithSizeLimit(1<<24))
var sizeLimit int64 = 1 << 24

resp, err := http.DefaultClient.Do(req)
if err != nil {
return fmt.Errorf("error performing request: %w", err)
}
defer resp.Body.Close()
// https://binance-docs.github.io/apidocs/websocket_api/en/#response-format
if resp.StatusCode != http.StatusOK {
var apiResp BNApiResponse
reader := io.LimitReader(resp.Body, sizeLimit)
if err = json.NewDecoder(reader).Decode(&apiResp); err != nil {
return fmt.Errorf("error decoding response: %w", err)
}
return fmt.Errorf("API error %d: %s (%d)", resp.StatusCode, apiResp.Msg, apiResp.Code)
}
Copy link
Member

Choose a reason for hiding this comment

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

Let's just add this functionality to dexnet. 50005f4...buck54321:dexnet-errparse

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.

4 participants