Skip to content

Commit

Permalink
update apiclient
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmenendez committed Jun 27, 2024
1 parent 678b055 commit fed1055
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
24 changes: 17 additions & 7 deletions apiclient/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,26 @@ package apiclient
import (
"fmt"
"net/url"
"path"
"strings"
)

const queryParamsSeparator = "?"

// constructURL constructs a URL from the base URL, endpoint and additional path elements
func (c *HTTPclient) constructURL(endpoint string, args ...string) (string, error) {
u, err := url.Parse(c.addr.String())
func (c *HTTPclient) constructURL(endpoint string) (string, error) {
if endpoint == "" {
return c.addr.String(), nil
}
// decode endpoint in paths and query parameters
parts := strings.SplitN(endpoint, queryParamsSeparator, 2)
finalEndpoint := c.addr.JoinPath(parts[0])
if len(parts) < 2 {
return finalEndpoint.String(), nil
}
queryParams, err := url.ParseQuery(parts[1])
if err != nil {
return "", fmt.Errorf("error parsing base URL: %v", err)
return "", fmt.Errorf("error parsing query parameters: %w", err)
}
allPaths := append([]string{endpoint}, args...)
u.Path = path.Join(append([]string{u.Path}, allPaths...)...)
return u.String(), nil
finalEndpoint.RawQuery = queryParams.Encode()
return finalEndpoint.String(), nil
}
3 changes: 3 additions & 0 deletions apiclient/tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ func (c *HTTPclient) TokenHolder(tokenID string, chainID uint64, externalID, hol
}
}()
if res.StatusCode != http.StatusOK {
if res.StatusCode == http.StatusNotFound {
return nil, nil
}
return nil, fmt.Errorf("%w: %w", ErrNoStatusOk, fmt.Errorf("%d %s", res.StatusCode, http.StatusText(res.StatusCode)))
}
// decode the response and return the token holder response
Expand Down

0 comments on commit fed1055

Please sign in to comment.