Skip to content

Commit

Permalink
Also show customizing the response.
Browse files Browse the repository at this point in the history
  • Loading branch information
jorendorff committed Jan 13, 2025
1 parent fb4f20a commit 6fd41bb
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions crates/twirp/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,23 @@ pub trait IntoTwirpResponse {
/// use axum::body::Body;
/// use http::Response;
/// use twirp::IntoTwirpResponse;
/// # struct MyError { message: &'static str }
/// # struct MyError { message: String }
///
/// impl IntoTwirpResponse for MyError {
/// fn into_twirp_response(self) -> Response<Body> {
/// twirp::invalid_argument(self.message)
/// .into_twirp_response()
/// // Use TwirpErrorResponse to generate a valid starting point
/// let mut response = twirp::invalid_argument(&self.message)
/// .into_twirp_response();
///
/// // Customize the response as desired.
/// response.headers_mut().insert("X-Server-Pid", std::process::id().into());
/// response
/// }
/// }
/// ```
///
/// The `Response` that `TwirpErrorResponse` generates can be used as a starting point,
/// adding headers and extensions to it.
fn into_twirp_response(self) -> Response<Body>;
}

Expand Down

0 comments on commit 6fd41bb

Please sign in to comment.