Release 0.3.0: capture error-response body, Duration timeout, non_exhaustive errors - #4
Merged
Conversation
…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.
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.
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
Httperror 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.Displayappends the body when present. This is the floor for debugging against a real API.Changed (breaking)
Duration.new/with_clienttakeimpl Into<Option<std::time::Duration>>instead ofOption<u64>milliseconds. PassDuration::from_secs(5)orNone(5s default). Kills the footgun whereSome(30)silently meant 30 milliseconds.#[non_exhaustive]andHttpgained abodyfield. Cross-crate exhaustivematches need a_arm.Migration
Docs, examples & tests
error_handling.rsexample — reading a failed request's body.DurationAPI and the error-body pattern.[0.3.0]with the breaking-change notes and migration.Verification
cargo fmt --check,cargo clippy --all-targets -- -D warnings, and 24 tests (incl. newtest_http_error_captures_body) + doctests + all examples — all green. The 19 original behavior tests are unchanged (only the mechanicalSome(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.