Skip to content

feat(token): integrate indexer provider#195

Draft
dhyaniarun1993 wants to merge 5 commits intomainfrom
arun/feat/integrate-indexer-provider
Draft

feat(token): integrate indexer provider#195
dhyaniarun1993 wants to merge 5 commits intomainfrom
arun/feat/integrate-indexer-provider

Conversation

@dhyaniarun1993
Copy link
Copy Markdown
Member

Closes #192

@dhyaniarun1993 dhyaniarun1993 self-assigned this Apr 8, 2026
@dhyaniarun1993 dhyaniarun1993 changed the title Arun/feat/integrate indexer provider feat(token): integrate indexer provider Apr 8, 2026
@dhyaniarun1993 dhyaniarun1993 marked this pull request as draft April 8, 2026 16:28
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces an alternative "indexer" mode for the token data provider, allowing the system to query balances and total supply via a pre-materialized HTTP API instead of live gRPC scans. Key changes include the implementation of an HTTP client for the indexer, a new indexer-backed provider, and configuration updates to support mode selection. Feedback was provided to improve the robustness of error handling in the indexer client by ensuring that raw response bodies are captured as a fallback when JSON error decoding fails for non-2xx status codes.

Comment on lines +222 to +237
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
// Best-effort decode of the indexer's JSON error envelope.
// If the body is not JSON (e.g. an HTML gateway error page), errMsg
// stays empty and the status code alone is returned to the caller.
var errMsg string
var body struct {
Error string `json:"error"`
}
if err := json.NewDecoder(resp.Body).Decode(&body); err == nil {
errMsg = body.Error
}
if resp.StatusCode == http.StatusNotFound {
return apperrors.ResourceNotFoundError(nil, errMsg)
}
return fmt.Errorf("indexer HTTP %d: %s", resp.StatusCode, errMsg)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The current error handling for non-2xx responses can hide important debugging information. If the response body isn't a valid JSON with an error field, the error message becomes empty, making it difficult to diagnose issues (e.g., indexer HTTP 500: ).

To make error handling more robust, I suggest reading the entire response body first. You can then use the raw body as a fallback error message if it cannot be parsed as the expected JSON error structure. This ensures a meaningful error message is always available.

Note: You'll need to add "io" to your imports for this change.

if resp.StatusCode < 200 || resp.StatusCode >= 300 {
		bodyBytes, err := io.ReadAll(resp.Body)
		if err != nil {
			return fmt.Errorf("indexer HTTP %d: failed to read error body: %w", resp.StatusCode, err)
		}

		var body struct {
			Error string `json:"error"`
		}
		// Default to the full body as the error message.
		errMsg := strings.TrimSpace(string(bodyBytes))
		// If we can parse the JSON error envelope, use that instead.
		if err := json.Unmarshal(bodyBytes, &body); err == nil && body.Error != "" {
			errMsg = body.Error
		}

		if resp.StatusCode == http.StatusNotFound {
			return apperrors.ResourceNotFoundError(nil, errMsg)
		}
		return fmt.Errorf("indexer HTTP %d: %s", resp.StatusCode, errMsg)
	}

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.

feat(config): make token data provider selectable or support multiple provider

1 participant