robustness: add HTTP status code checks to market data & provider APIs

- market/api_client.go: check StatusCode for exchangeInfo, klines, price
  endpoints + add truncateBody helper for safe error messages
- market/data.go: check StatusCode for openInterest and premiumIndex
- provider/coinank: check StatusCode for GET and POST requests
- provider/twelvedata: check StatusCode for time series and quote APIs
- Prevents confusing JSON unmarshal errors when APIs return 429/500/etc
This commit is contained in:
shinchan-zhai
2026-03-23 11:00:24 +08:00
parent 3c698e3fc5
commit 88f6fa7911
5 changed files with 40 additions and 1 deletions

View File

@@ -71,6 +71,9 @@ func get(ctx context.Context, path string, paramsMap map[string]string) (string,
if err != nil {
return "", err
}
if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("CoinAnk API error (status %d): %.512s", resp.StatusCode, string(body))
}
return string(body), nil
}