1use std::fmt::Display;
19
20use http::StatusCode;
21
22use crate::{dcdn::interpret::Error, logging::LogMsgs};
23
24pub type ProxyValue = (StatusCode, http::Response<Vec<u8>>, LogMsgs);
25pub type ProxyResult = Result<ProxyValue, (Box<ProxyError>, LogMsgs)>;
26
27#[derive(Debug)]
28pub enum ProxyError {
29 SetupError(Box<dyn std::error::Error>),
30 HmdsError(Box<dyn std::error::Error>),
31 ImdiError(ImdInterpretError),
32 NativeError(Box<dyn std::error::Error>),
33}
34
35impl Display for ProxyError {
36 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
37 write!(f, "Error proxying to/from the native request: ")?;
38 match &self {
39 ProxyError::SetupError(error) => write!(f, "{error}"),
40 ProxyError::HmdsError(error) => write!(f, "{error}"),
41 ProxyError::ImdiError(imd_interpret_error) => write!(f, "{imd_interpret_error}"),
42 ProxyError::NativeError(native_error) => write!(f, "{native_error}"),
43 }
44 }
45}
46
47pub type ImdInterpretValue = (StatusCode, http::Response<Vec<u8>>, LogMsgs);
48pub type ImdInterpretResultError = (Box<ImdInterpretError>, LogMsgs);
49pub type ImdInterpretResult = Result<ImdInterpretValue, (Box<ImdInterpretError>, LogMsgs)>;
50
51#[derive(Debug)]
52pub enum ImdInterpretError {
53 TransformError(Box<dyn std::error::Error>),
54 UpstreamError(String),
55 RuntimeError(Box<dyn std::error::Error>),
56 MetadataProcessingError(Box<Error>),
57}
58
59impl Display for ImdInterpretError {
60 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
61 write!(f, "Interconnection Metadata Interpretation Error: ")?;
62 match self {
63 ImdInterpretError::MetadataProcessingError(ps_interpret_error) => {
64 write!(f, "{ps_interpret_error}")
65 }
66 ImdInterpretError::UpstreamError(ue) => {
67 write!(f, "{ue}")
68 }
69 ImdInterpretError::RuntimeError(re) => {
70 write!(f, "{re}")
71 }
72 ImdInterpretError::TransformError(te) => write!(f, "{te}"),
73 }
74 }
75}
76
77impl std::error::Error for ImdInterpretError {}