use super::{Node, NodeContext, NodeKind, NodeRequest, NodeResponse}; use crate::error::ServiceError; use futures::Future; use serde::Deserialize; use serde_yml::Value; use std::{pin::Pin, sync::Arc}; pub struct ErrorKind; #[derive(Deserialize)] #[serde(transparent)] struct Error(String); impl NodeKind for ErrorKind { fn name(&self) -> &'static str { "error" } fn instanciate(&self, config: Value) -> anyhow::Result> { Ok(Arc::new(serde_yml::from_value::(config)?)) } } impl Node for Error { fn handle<'a>( &'a self, _context: &'a mut NodeContext, _request: NodeRequest, ) -> Pin> + Send + Sync + 'a>> { Box::pin(async move { Err(ServiceError::Custom(self.0.clone())) }) } }