Skip to main content

a3s_boot/pipeline/
filter.rs

1use super::ExecutionContext;
2use crate::{BootError, BootResponse, BoxFuture, Result};
3
4/// Maps route/pipeline errors to HTTP responses.
5pub trait ExceptionFilter: Send + Sync + 'static {
6    fn catch(
7        &self,
8        context: ExecutionContext,
9        error: BootError,
10    ) -> BoxFuture<'static, Result<Option<BootResponse>>>;
11}
12
13impl<F, Fut> ExceptionFilter for F
14where
15    F: Fn(ExecutionContext, BootError) -> Fut + Send + Sync + 'static,
16    Fut: std::future::Future<Output = Result<Option<BootResponse>>> + Send + 'static,
17{
18    fn catch(
19        &self,
20        context: ExecutionContext,
21        error: BootError,
22    ) -> BoxFuture<'static, Result<Option<BootResponse>>> {
23        Box::pin(self(context, error))
24    }
25}