fix: handle opensea v2 api error for accounts holding no collectibles
This commit is contained in:
parent
c494904f18
commit
8d8bd4fc92
|
@ -25,9 +25,9 @@ const assetLimitV2 = 50
|
|||
func getV2BaseURL(chainID walletCommon.ChainID) (string, error) {
|
||||
switch uint64(chainID) {
|
||||
case walletCommon.EthereumMainnet, walletCommon.ArbitrumMainnet, walletCommon.OptimismMainnet:
|
||||
return "https://api.opensea.io/api/v2", nil
|
||||
return "https://api.opensea.io/v2", nil
|
||||
case walletCommon.EthereumGoerli, walletCommon.EthereumSepolia, walletCommon.ArbitrumGoerli, walletCommon.OptimismGoerli:
|
||||
return "https://testnets-api.opensea.io/api/v2", nil
|
||||
return "https://testnets-api.opensea.io/v2", nil
|
||||
}
|
||||
|
||||
return "", thirdparty.ErrChainIDNotSupported
|
||||
|
@ -156,6 +156,13 @@ func (o *ClientV2) fetchAssets(chainID walletCommon.ChainID, pathParams []string
|
|||
}
|
||||
o.connectionStatus.SetIsConnected(true)
|
||||
|
||||
// If body is empty, it means the account has no collectibles for this chain.
|
||||
// (Workaround implemented in http_client.go)
|
||||
if body == nil {
|
||||
assets.NextCursor = ""
|
||||
break
|
||||
}
|
||||
|
||||
// if Json is not returned there must be an error
|
||||
if !json.Valid(body) {
|
||||
return nil, fmt.Errorf("invalid json: %s", string(body))
|
||||
|
|
|
@ -65,6 +65,10 @@ func (o *HTTPClient) doGetRequest(url string, apiKey string) ([]byte, error) {
|
|||
case http.StatusOK:
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
return body, err
|
||||
case http.StatusBadRequest:
|
||||
// The OpenSea v2 API will return error 400 if the account holds no collectibles on
|
||||
// the requested chain. This shouldn't be treated as an error, return an empty body.
|
||||
return nil, nil
|
||||
case http.StatusTooManyRequests:
|
||||
if retryCount < getRequestRetryMaxCount {
|
||||
// sleep and retry
|
||||
|
|
Loading…
Reference in New Issue