Skip to content

Commit

Permalink
feat: implement Reply for Result<impl Reply, impl Reply> (#909)
Browse files Browse the repository at this point in the history
  • Loading branch information
gtsiam committed Jul 21, 2023
1 parent e562afa commit da47391
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/reply.rs
Expand Up @@ -411,18 +411,24 @@ impl Reply for ::http::StatusCode {
}
}

impl<T> Reply for Result<T, ::http::Error>
impl Reply for ::http::Error {
#[inline]
fn into_response(self) -> Response {
tracing::error!("reply error: {:?}", self);
StatusCode::INTERNAL_SERVER_ERROR.into_response()
}
}

impl<T, E> Reply for Result<T, E>
where
T: Reply + Send,
T: Reply,
E: Reply,
{
#[inline]
fn into_response(self) -> Response {
match self {
Ok(t) => t.into_response(),
Err(e) => {
tracing::error!("reply error: {:?}", e);
StatusCode::INTERNAL_SERVER_ERROR.into_response()
}
Err(e) => e.into_response(),
}
}
}
Expand Down

0 comments on commit da47391

Please sign in to comment.