use crate::blueprint::ErrorHandler;
use crate::blueprint::conversions::coordinates2coordinates;
use pavex_bp_schema::{Blueprint as BlueprintSchema, Component, Location};
use super::reflection::AnnotationCoordinates;
pub struct Fallback {
#[doc(hidden)]
pub coordinates: AnnotationCoordinates,
}
pub struct RegisteredFallback<'a> {
pub(crate) blueprint: &'a mut BlueprintSchema,
pub(crate) component_id: usize,
}
impl RegisteredFallback<'_> {
#[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.fallback().error_handler = Some(error_handler);
self
}
fn fallback(&mut self) -> &mut pavex_bp_schema::Fallback {
let component = &mut self.blueprint.components[self.component_id];
let Component::FallbackRequestHandler(fallback) = component else {
unreachable!("The component should be a fallback request handler")
};
fallback
}
}