Skip to content

Commit

Permalink
fix merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Dyas committed Jun 22, 2021
1 parent 8edb9ac commit 92aaafe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
16 changes: 12 additions & 4 deletions tonic/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,19 +305,27 @@ impl Status {
}

#[cfg_attr(not(feature = "transport"), allow(dead_code))]
pub(crate) fn from_error(err: Box<dyn Error + 'static>) -> Status {
pub(crate) fn from_error(err: Box<dyn Error + Send + Sync + 'static>) -> Status {
Status::try_from_error(err)
.unwrap_or_else(|err| Status::new(Code::Unknown, err.to_string()))
}

pub(crate) fn try_from_error(err: Box<dyn Error + 'static>) -> Result<Status, Box<dyn Error + 'static>> {
pub(crate) fn try_from_error(
err: Box<dyn Error + Send + Sync + 'static>,
) -> Result<Status, Box<dyn Error + Send + Sync + 'static>> {
let err = match err.downcast::<Status>() {
Ok(status) => {
return Ok(*status);
}
Err(err) => err,
};

#[cfg(feature = "transport")]
let err = match err.downcast::<crate::transport::TimeoutExpired>() {
Ok(timeout) => return Ok(Status::cancelled(timeout.to_string())),
Err(err) => err,
};

#[cfg(feature = "transport")]
let err = match err.downcast::<h2::Error>() {
Ok(h2) => {
Expand Down Expand Up @@ -586,9 +594,9 @@ fn invalid_header_value_byte<Error: fmt::Display>(err: Error) -> Status {
}

impl TryFrom<Box<dyn Error + Send + Sync + 'static>> for Status {
type Error = Box<dyn Error + 'static>;
type Error = Box<dyn Error + Send + Sync + 'static>;

fn try_from(err: Box<dyn Error + Send + Sync>) -> Result<Self, Self::Error> {
fn try_from(err: Box<dyn Error + Send + Sync + 'static>) -> Result<Self, Self::Error> {
Status::try_from_error(err)
}
}
Expand Down
9 changes: 4 additions & 5 deletions tonic/src/transport/server/recover_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,14 @@ where
let response = response.map(MaybeEmptyBody::full);
Poll::Ready(Ok(response))
}
Err(err) => {
if let Some(status) = Status::try_from_error(&*err) {
Err(err) => match Status::try_from_error(err) {
Ok(status) => {
let mut res = Response::new(MaybeEmptyBody::empty());
status.add_header(res.headers_mut()).unwrap();
Poll::Ready(Ok(res))
} else {
Poll::Ready(Err(err))
}
}
Err(err) => Poll::Ready(Err(err)),
},
}
}
}
Expand Down

0 comments on commit 92aaafe

Please sign in to comment.