Skip to content

Release 0.3.0: capture error-response body, Duration timeout, non_exhaustive errors - #4

Merged
azeemshaik025 merged 3 commits into
mainfrom
feat/v0.3.0
Aug 9, 2026
Merged

Release 0.3.0: capture error-response body, Duration timeout, non_exhaustive errors#4
azeemshaik025 merged 3 commits into
mainfrom
feat/v0.3.0

Conversation

@azeemshaik025

Copy link
Copy Markdown
Owner

Summary

Breaking 0.3.0 — the trust-bar items from the review. Two breaking changes (constructor signature, error enum), one behind-the-scenes win.

Added

  • The Http error variant now carries the response body. A non-2xx response keeps the raw payload the server returned — Http { status, reason, body } — so the reason a request was rejected is no longer discarded. Display appends the body when present. This is the floor for debugging against a real API.

Changed (breaking)

  • Timeout is now a Duration. new / with_client take impl Into<Option<std::time::Duration>> instead of Option<u64> milliseconds. Pass Duration::from_secs(5) or None (5s default). Kills the footgun where Some(30) silently meant 30 milliseconds.
  • The generated error enum is #[non_exhaustive] and Http gained a body field. Cross-crate exhaustive matches need a _ arm.

Migration

// before
let client = UserApi::new(url, Some(5000));
Err(UserApiError::Http { status, reason }) => { /* body was gone */ }

// after
let client = UserApi::new(url, Duration::from_secs(5));   // or None for the default
Err(UserApiError::Http { status, reason, body }) => { eprintln!("{status}: {body}"); }

Docs, examples & tests

  • New error_handling.rs example — reading a failed request's body.
  • Every example, the README (new Errors section), and the crate doctest moved to the Duration API and the error-body pattern.
  • CHANGELOG [0.3.0] with the breaking-change notes and migration.

Verification

cargo fmt --check, cargo clippy --all-targets -- -D warnings, and 24 tests (incl. new test_http_error_captures_body) + doctests + all examples — all green. The 19 original behavior tests are unchanged (only the mechanical Some(5000)Duration::from_secs(5) swap), so nothing existing regressed.

Not in this release

Typed error bodies (the err: DSL, #2 from the plan) — deferred; it builds on the raw-body capture landed here and wants its own design pass.

…austive errors

Breaking changes to the constructor signature and the generated error enum.

Added:
- The `Http` error variant now carries the response body
  (`Http { status, reason, body }`), so a non-2xx response no longer discards the
  server's explanation. `Display` includes the body when present.

Changed (breaking):
- `new` / `with_client` take the timeout as `impl Into<Option<Duration>>` instead of
  `Option<u64>` milliseconds — pass a `Duration` or `None` (5s default). Removes the
  `Some(30)`-means-30ms footgun.
- The generated error enum is now `#[non_exhaustive]` and `Http` gained a `body` field.

Docs, examples & tests:
- New `error_handling.rs` example showing how to read a failed request's body.
- All examples, the README, and the crate doctest updated to the `Duration` API and
  the error-body pattern; CHANGELOG entry for 0.3.0.
- Added `test_http_error_captures_body`; all timeout call sites moved to `Duration`.
…ases

The initial change had only one error-body test (422 + JSON on the non-retry
path). Add cases for an empty body, a non-JSON body, and the separate retry-path
branch, plus Display-formatting assertions.
The Duration timeout signature is impl Into<Option<Duration>>; the README documents
passing None for the 5s default, but every other test passes an explicit Duration.
Lock in that None compiles and works end to end.
@azeemshaik025
azeemshaik025 merged commit bb3dfd9 into main Aug 9, 2026
1 check passed
@azeemshaik025
azeemshaik025 deleted the feat/v0.3.0 branch August 9, 2026 06:21
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.

1 participant