use crate::blueprint::conversions::raw_callable2registered_callable;
use crate::blueprint::middleware::pre::RegisteredPreProcessingMiddleware;
use crate::blueprint::reflection::RawCallable;
use crate::blueprint::Blueprint;
use pavex_bp_schema::Callable;
#[derive(Clone, Debug)]
pub struct PreProcessingMiddleware {
pub(in crate::blueprint) callable: Callable,
pub(in crate::blueprint) error_handler: Option<Callable>,
}
impl PreProcessingMiddleware {
#[track_caller]
pub fn new(callable: RawCallable) -> Self {
Self {
callable: raw_callable2registered_callable(callable),
error_handler: None,
}
}
#[track_caller]
pub fn error_handler(mut self, error_handler: RawCallable) -> Self {
self.error_handler = Some(raw_callable2registered_callable(error_handler));
self
}
pub fn register(self, bp: &mut Blueprint) -> RegisteredPreProcessingMiddleware {
bp.register_pre_processing_middleware(self)
}
}