diff --git a/apiclient/helpers.go b/apiclient/helpers.go index 8d710246..d0db309a 100644 --- a/apiclient/helpers.go +++ b/apiclient/helpers.go @@ -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 } diff --git a/apiclient/tokens.go b/apiclient/tokens.go index e6b38dbf..9de43ece 100644 --- a/apiclient/tokens.go +++ b/apiclient/tokens.go @@ -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