Skip to content

Commit 6fd41bb

Browse files
committed
Also show customizing the response.
1 parent fb4f20a commit 6fd41bb

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

crates/twirp/src/error.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,23 @@ pub trait IntoTwirpResponse {
1818
/// use axum::body::Body;
1919
/// use http::Response;
2020
/// use twirp::IntoTwirpResponse;
21-
/// # struct MyError { message: &'static str }
21+
/// # struct MyError { message: String }
2222
///
2323
/// impl IntoTwirpResponse for MyError {
2424
/// fn into_twirp_response(self) -> Response<Body> {
25-
/// twirp::invalid_argument(self.message)
26-
/// .into_twirp_response()
25+
/// // Use TwirpErrorResponse to generate a valid starting point
26+
/// let mut response = twirp::invalid_argument(&self.message)
27+
/// .into_twirp_response();
28+
///
29+
/// // Customize the response as desired.
30+
/// response.headers_mut().insert("X-Server-Pid", std::process::id().into());
31+
/// response
2732
/// }
2833
/// }
2934
/// ```
35+
///
36+
/// The `Response` that `TwirpErrorResponse` generates can be used as a starting point,
37+
/// adding headers and extensions to it.
3038
fn into_twirp_response(self) -> Response<Body>;
3139
}
3240

0 commit comments

Comments
 (0)