Skip to content

Commit

Permalink
expose Extensions::into_http and Status::from_error (#1067)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdahlq authored Aug 24, 2022
1 parent 523a550 commit 2a83f8b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion tonic/src/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::fmt;
///
/// [`Interceptor`]: crate::service::Interceptor
/// [`Request`]: crate::Request
#[derive(Default)]
pub struct Extensions {
inner: http::Extensions,
}
Expand Down Expand Up @@ -58,8 +59,9 @@ impl Extensions {
Self { inner: http }
}

/// Convert to `http::Extensions` and consume self.
#[inline]
pub(crate) fn into_http(self) -> http::Extensions {
pub fn into_http(self) -> http::Extensions {
self.inner
}
}
Expand Down
6 changes: 5 additions & 1 deletion tonic/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,12 @@ impl Status {
Self::from_error(err.into())
}

/// Create a `Status` from various types of `Error`.
///
/// Inspects the error source chain for recognizable errors, including statuses, HTTP2, and
/// hyper, and attempts to maps them to a `Status`, or else returns an Unknown `Status`.
#[cfg_attr(not(feature = "transport"), allow(dead_code))]
pub(crate) fn from_error(err: Box<dyn Error + Send + Sync + 'static>) -> Status {
pub fn from_error(err: Box<dyn Error + Send + Sync + 'static>) -> Status {
Status::try_from_error(err).unwrap_or_else(|err| {
let mut status = Status::new(Code::Unknown, err.to_string());
status.source = Some(err);
Expand Down

0 comments on commit 2a83f8b

Please sign in to comment.