Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add handle_error to ServiceExt #2235

Merged
merged 7 commits into from
Nov 24, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add handle_error function to ServiceExt trait
  • Loading branch information
GuillerLT committed Sep 19, 2023
commit 6de881c27d526a73562ff7dbd09b56a870092af8
14 changes: 14 additions & 0 deletions axum/src/service_ext.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::error_handling::HandleError;
#[cfg(feature = "tokio")]
use crate::extract::connect_info::IntoMakeServiceWithConnectInfo;
use crate::routing::IntoMakeService;
@@ -30,6 +31,15 @@ pub trait ServiceExt<R>: Service<R> + Sized {
/// [`ConnectInfo`]: crate::extract::connect_info::ConnectInfo
#[cfg(feature = "tokio")]
fn into_make_service_with_connect_info<C>(self) -> IntoMakeServiceWithConnectInfo<Self, C>;

/// Convert this service into a [`HandleError`], that will handle errors
/// by converting them into responses.
///
/// See ["error handling model"] for more details.
///
/// [`HandleError`]: crate::error_handling::HandleError
/// ["error handling model"]: crate::error_handling#axums-error-handling-model
fn handle_error<F, T>(self, f: F) -> HandleError<Self, F, T>;
}

impl<S, R> ServiceExt<R> for S
@@ -44,4 +54,8 @@ where
fn into_make_service_with_connect_info<C>(self) -> IntoMakeServiceWithConnectInfo<Self, C> {
IntoMakeServiceWithConnectInfo::new(self)
}

fn handle_error<F, T>(self, f: F) -> HandleError<Self, F, T> {
HandleError::new(self, f)
}
}