blob: 6e895d0966e26c439d86cb20f81eed224881aa7b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
/*
This file is part of gnix (https://codeberg.org/metamuffin/gnix)
which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
Copyright (C) 2025 metamuffin <metamuffin.org>
*/
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<Arc<dyn Node>> {
Ok(Arc::new(serde_yml::from_value::<Error>(config)?))
}
}
impl Node for Error {
fn handle<'a>(
&'a self,
_context: &'a mut NodeContext,
_request: NodeRequest,
) -> Pin<Box<dyn Future<Output = Result<NodeResponse, ServiceError>> + Send + Sync + 'a>> {
Box::pin(async move { Err(ServiceError::Custom(self.0.clone())) })
}
}
|