Skip to content

feat!: preserve API error responses and expose Problem details - #295

Merged
matoous merged 4 commits into
mainfrom
md/problem-errors
Oct 26, 2026
Merged

matoous merged 4 commits into
mainfrom
md/problem-errors

Conversation

@matoous

@matoous matoous commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

API failures now retain their HTTP status, headers, and original response bytes alongside typed bodies. error.problem() provides typed Problem details for documented and unrecognized Problem responses, including endpoints that do not describe their error body.

if let Err(error) = client.checkouts().get("your-checkout-id").await {
    if let Some(problem) = error.problem() {
        println!("{}: {:?}", problem.r#type, problem.detail);
    }
    println!("{:?}", error.status());
}

Malformed documented error bodies remain HTTP failures with their original bytes instead of becoming network errors. Resource calls and event-object fetching share this behavior. If reading the body fails, status and headers remain available and the original error is retained as the cause.

Compatibility: Body-read failures now use SdkError::Response instead of SdkError::Network; exhaustive matches need to handle this variant. SdkError::Api(response) and SdkError::Unexpected(response) now contain a boxed ApiErrorResponse. When matching either variant, read its typed or fallback payload through response.body. Existing body() and into_body() helpers continue to expose the endpoint-specific body. The old api and unexpected constructors are replaced by the response-aware construction paths.

The new reader and token endpoints on current main use the same error handling.

The README shows the common error handling path beside SDK usage, with access to the original response for other error details.

Related to sumup/sumup-py#434 and the Python SDK changes in sumup/sumup-py#436.

Expose typed Problem details and preserve error response context. Add focused
regression coverage and concise integration examples.

BREAKING CHANGE: API error variants now contain boxed ApiErrorResponse values.
Read the payload through response.body when matching variants.
@matoous matoous self-assigned this Oct 26, 2026
Represent interrupted response bodies separately from connection failures. Keep the received status and headers alongside the original cause for documented and unexpected errors.
Merge current main and regenerate reader and token methods with response-aware API errors and typed Problem access.
Keep typed Problem access available when an endpoint does not describe its error body. Simplify the README and API documentation around the common error handling path.
@matoous
matoous marked this pull request as ready for review October 26, 2026 18:42
@matoous
matoous merged commit b1b06f6 into main Oct 26, 2026
10 checks passed
@matoous
matoous deleted the md/problem-errors branch October 26, 2026 18:42
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