Repository navigation
API client cleanup + cargo fmt enforcement - #17
Merged
Merged
Conversation
JohanLorenzo
approved these changes
Jun 25, 2026
JohanLorenzo
left a comment
Collaborator
There was a problem hiding this comment.
Thank you for centralizing these 2 behaviors! LGTM 👌
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This branch refactors the Redash API client (
src/api.rs) to remove duplicated request/error-handling boilerplate, and tightens the developer tooling.1.
Make API error handling uniform(9d55eb1)Every API method previously inlined its own error-status check, and they had drifted: some used
.error_for_status()with the generic context"API returned error status", others hand-rolledanyhow::bail!("HTTP {status}: ..."), some included the response body and some didn't. The messages were inconsistent and several discarded the server's error body — the most useful part for debugging.All of these are replaced by a single helper:
Why it's beneficial:
API error {status}: {body}) across the whole client, always including the server body.statusalreadyDisplays the canonical reason (e.g.404 Not Found), so no manual reason lookup.get_with_retry) now routes through the same helper instead of duplicating the check.src/api.rs.2.
Introduce get_json and post_json helpers(8676e93)Builds on the uniform error handling. Most methods followed the identical shape: build URL → send →
ensure_success→.json()→ context-wrapped parse. Two generic helpers capture this:Methods collapse to a URL plus a one-line call, e.g.:
Why it's beneficial:
ctxstring drives both failure messages (Failed to request {ctx}/Failed to parse {ctx} response), keeping request and parse errors consistent.()responses or retries still useensure_success/get_with_retrydirectly.3.
Enforce cargo fmt on developer side(e2e66ee)Adds a
cargo fmt -- --checkpre-commit hook alongside the existing clippy hook.Why it's beneficial:
cargo fmtwas already enforced in CI; this catches formatting issues locally before push, avoiding round-trip CI failures.Notes
CLAUDE.mdis updated in each commit to document the new helpers and thecargo fmtconstraint.src/api.rs.