diff --git a/tonic/src/status.rs b/tonic/src/status.rs index fb73863..1b83c62 100644 --- a/tonic/src/status.rs +++ b/tonic/src/status.rs @@ -325,7 +325,14 @@ impl Status { }) } - pub(crate) fn try_from_error( + /// Create a `Status` from various types of `Error`. + /// + /// Returns the error if a status could not be created. + /// + /// # Downcast stability + /// This function does not provide any stability guarantees around how it will downcast errors into + /// status codes. + pub fn try_from_error( err: Box, ) -> Result> { let err = match err.downcast::() { @@ -501,7 +508,8 @@ impl Status { Ok(header_map) } - pub(crate) fn add_header(&self, header_map: &mut HeaderMap) -> Result<(), Self> { + /// Add headers from this `Status` into `header_map`. + pub fn add_header(&self, header_map: &mut HeaderMap) -> Result<(), Self> { header_map.extend(self.metadata.clone().into_sanitized_headers()); header_map.insert(GRPC_STATUS_HEADER_CODE, self.code.to_header_value()); @@ -555,6 +563,12 @@ impl Status { } } + /// Add a source error to this status. + pub fn set_source(&mut self, source: Arc) -> &mut Status { + self.source = Some(source); + self + } + #[allow(clippy::wrong_self_convention)] /// Build an `http::Response` from the given `Status`. pub fn to_http(self) -> http::Response {