Skip to content

Add SDK error type for custom error propagation - #13

Open
manish-raana wants to merge 1 commit into
openapi:mainfrom
manish-raana:main
Open

manish-raana wants to merge 1 commit into
openapi:mainfrom
manish-raana:main

Conversation

@manish-raana

Copy link
Copy Markdown

Fixes #11.

This change adds a public openapi_sdk::Error type and openapi_sdk::Result alias so downstream projects can integrate SDK failures into their own error enums with From<openapi_sdk::Error> and
continue using ? in existing Result pipelines.

Changes

  • Added openapi_sdk::Error with variants for HTTP errors, invalid headers, and invalid HTTP methods.
  • Implemented Display, std::error::Error, and From conversions for wrapped error types.
  • Replaced panic-prone unwrap() calls for header and method parsing with returned SDK errors.
  • Added error_for_status() handling for non-2xx HTTP responses.
  • Added regression tests for custom error propagation.
  • Documented custom error integration in README and crates.io docs.

Verification

  • cargo fmt --all -- --check
  • cargo test
  • cargo test --examples

@francescobianco francescobianco left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approved, thank you! See my comment below for the merge order.

@francescobianco

Copy link
Copy Markdown
Member

@manish-raana thank you so much for this! 🙏 A real openapi_sdk::Error with From conversions is exactly what #11 asked for: downstream crates can finally use ? with their own error enums, the unwrap()s on headers and methods are gone, and the regression tests pass (6/6 locally). Approved.

One thing about timing: @LucaCappelletti94 is running a short series to harden the crate's CI (#14 merged, #15 lint gates and #16 semver checks next). Once those land, this PR will need a rebase:

Also a small design question, not blocking: error_for_status() drops the response body, and Openapi's error bodies usually say why a call failed. Would it be worth an Error::Api { status, body } variant that keeps it?

I'll ping you here as soon as #15 and #16 are in. Thank you!

@francescobianco

Copy link
Copy Markdown
Member

One more thing: you'd be very welcome in the official Openapi® contributors registry → https://github.com/openapi/contributors. Fork it, add your row (template in the README) with openapi/openapi-rust-sdk as your main project, and open a PR. If you like, add the badge to your profile README too:

[![Openapi® Contributor](https://img.shields.io/badge/Openapi%C2%AE-Contributor-753f8b)](https://github.com/openapi/contributors)

Thank you! 🚀

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.

Propagating Openapi SDK errors in existing Result pipeline

2 participants