Skip to main content

lmn_core/response_template/
error.rs

1use std::io;
2
3#[derive(Debug)]
4pub enum ResponseTemplateError {
5    Io(io::Error),
6    InvalidJson(serde_json::Error),
7    InvalidFieldType(String),
8}
9
10impl std::fmt::Display for ResponseTemplateError {
11    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
12        match self {
13            Self::Io(e) => write!(f, "failed to read response template file: {e}"),
14            Self::InvalidJson(e) => write!(f, "response template is not valid JSON: {e}"),
15            Self::InvalidFieldType(t) => {
16                write!(
17                    f,
18                    "unsupported response field type '{t}' — expected STRING or FLOAT"
19                )
20            }
21        }
22    }
23}
24
25impl std::error::Error for ResponseTemplateError {}
26
27impl From<io::Error> for ResponseTemplateError {
28    fn from(e: io::Error) -> Self {
29        Self::Io(e)
30    }
31}
32
33impl From<serde_json::Error> for ResponseTemplateError {
34    fn from(e: serde_json::Error) -> Self {
35        Self::InvalidJson(e)
36    }
37}