use super::reflection::AnnotationCoordinates;
use crate::blueprint::ErrorHandler;
use crate::blueprint::conversions::coordinates2coordinates;
use pavex_bp_schema::{Blueprint as BlueprintSchema, Component, Location};
pub struct WrappingMiddleware {
#[doc(hidden)]
pub coordinates: AnnotationCoordinates,
}
pub struct RegisteredWrappingMiddleware<'a> {
pub(crate) blueprint: &'a mut BlueprintSchema,
pub(crate) component_id: usize,
}
impl RegisteredWrappingMiddleware<'_> {
#[track_caller]
pub fn error_handler(mut self, error_handler: ErrorHandler) -> Self {
let error_handler = pavex_bp_schema::ErrorHandler {
coordinates: coordinates2coordinates(error_handler.coordinates),
registered_at: Location::caller(),
};
self.wrapping_middleware().error_handler = Some(error_handler);
self
}
fn wrapping_middleware(&mut self) -> &mut pavex_bp_schema::WrappingMiddleware {
let component = &mut self.blueprint.components[self.component_id];
let Component::WrappingMiddleware(c) = component else {
unreachable!("The component should be a wrapping middleware")
};
c
}
}